简体   繁体   English

locationClient.requestLocationUpdates不会触发Kitkat中的Pending Intent

[英]locationClient.requestLocationUpdates doesn't fires Pending Intent in Kitkat

I have a code that works fine in Android 4.3 and below. 我有一个在Android 4.3及更低版本中运行良好的代码。 But the same code doesn't work in 4.4 android. 但是相同的代码在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
    }
}

I encounter the same problem only with Nexus 5. See here No answers yet, though. 我只在Nexus 5遇到同样的问题。但是,请看这里没有答案。 I tried changing FLAG_UPDATE_CURRENT to FLAG_CANCEL_CURRENT as suggested here . 我尝试将FLAG_UPDATE_CURRENT更改为FLAG_CANCEL_CURRENT,如此处所示 That did not solve it either. 这也没有解决它。

Lately I updated the google-play-service_lib 最近我更新了google-play-service_lib

and changed the locationClient.requestLocationUpdates method to LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, mPendingIntent); 并将locationClient.requestLocationUpdates方法更改为LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, mPendingIntent);

Now everything seems working fine on all versions. 现在一切似乎都适用于所有版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM