문제

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
    }
}
도움이 되었습니까?

해결책 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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top