Question

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
    }
}
Was it helpful?

Solution 2

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.

OTHER TIPS

I encounter the same problem only with Nexus 5. See here No answers yet, though. I tried changing FLAG_UPDATE_CURRENT to FLAG_CANCEL_CURRENT as suggested here. That did not solve it either.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top