This article describes the problem of determining whether the service is running and positioning on Android. Share it for your reference. The details are as follows:
/** * Determine whether the service is running * * @param context * @param className The service name judged: package name + class name * @return true running false not running */ public static boolean isServiceRunning(Context context, String className) { boolean isRunning = false; ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); //Get all services List<> services= (Integer.MAX_VALUE); if(services!=null&&()>0){ for( service : services){ if((())){ isRunning=true; break; } } } return isRunning; }
In Android development, we often use () to obtain latitude and longitude regularly. Some can be obtained in different real machine tests. Some cannot be obtained. In order to solve the compatibility of different mobile phones, please use the following code
public static Location getLocation(LocationManager locationManager, LocationListener locationListener) { Location location=null; location = (LocationManager.GPS_PROVIDER); (LocationManager.GPS_PROVIDER, 0, 0, locationListener); if(location==null){ location = (LocationManager.NETWORK_PROVIDER); (LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); } return location; }
I hope this article will be helpful to everyone's Android programming design.