我的代码在 Android 4.3 及以下版本中运行良好。但是相同的代码在 4.4 android 中不起作用。如果有人知道这个问题,请提供帮助。
下面是代码,
@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);
}
下面是我的服务类,
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
}
}
最佳答案
我只在 Nexus 5 上遇到过同样的问题。参见 here 不过,还没有答案。我尝试按照建议将 FLAG_UPDATE_CURRENT 更改为 FLAG_CANCEL_CURRENT here .那也没有解决它。
关于android - locationClient.requestLocationUpdates 不会触发 Kitkat 中的 Pending Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23536897/