This article illustrates the problem of whether or not the Android Judgment service is running and locating. Share to everyone for your reference. Specifically as follows:
/**
* To determine if the service is running
*
@param context
* @param className The service name of the judgment: Package name + class name
* @return true not running on false
*/public
Static Boolean isservicerunning (context context, String ClassName) {
Boolean isrunning = false;
Activitymanager Activitymanager = (activitymanager) context
. Getsystemservice (context.activity_service);
Get all the Services
list<activitymanager.runningserviceinfo> services= activitymanager.getrunningservices ( Integer.max_value);
if (Services!=null&&services.size () >0) {for
(Activitymanager.runningserviceinfo service:services) {
if (classname.equals (Service.service.getClassName ())) {
isrunning=true;
break;
}
}} return isrunning;
}
In the Android development, often use locationmanager.getlastknownlocation () time to obtain latitude and longitude, in the different true machine test some can get 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.getlastknownlocation (Locationmanager.gps_provider);
Locationmanager.requestlocationupdates (locationmanager.gps_provider, 0, 0, locationlistener);
if (location==null) {
location = locationmanager.getlastknownlocation (Locationmanager.network_provider);
Locationmanager.requestlocationupdates (locationmanager.network_provider, 0, 0, locationlistener);
return location;
}
I hope this article will help you with your Android program.