I have a code that works fine in Android 4.3 and below. But the same code doesn't work in 4.4 android. Please help if anyone knows about the issue.
Below is the code,
@Override
public void onConnected(Bundle arg0) {
Log.i(TAG, "location client connected");
locationRequest = new LocationRequest();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(2 * 60 * 1000);
locationRequest.setFastestInterval(1 *60 * 1000);
mIntentService = new Intent(context, MyService.class);
mPendingIntent = PendingIntent.getService(context, 0, mIntentService, PendingIntent.FLAG_UPDATE_CURRENT);
locationClient.requestLocationUpdates(locationRequest, mPendingIntent);
}
Below is my Service class,
public class MyService extends IntentService {
private String TAG = this.getClass().getSimpleName();
Context context;
public MyService () {
super("MyService ");
context = this;
}
public MyService (String name) {
super("MyService ");
}
@Override
protected void onHandleIntent(Intent intent) {
// my code
}
}
Lately I updated the google-play-service_lib
and changed the locationClient.requestLocationUpdates
method to LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, mPendingIntent);
Now everything seems working fine on all versions.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.