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

标签 android android-pendingintent android-4.4-kitkat

我的代码在 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/

相关文章:

android - Android 4.4 KitKat 上的 SMS 实用程序

java - 如何将 double 转换为小数点后两位?

android - cordova 构建在升级后出现 EACCES 错误

android - Ellipsize - 开始在 TextView 中不起作用

android - 为通知的未决 Intent 设置不同的 Activity

android - 如何正确地将独特的附加内容传递给待处理的 Intent ?

android - Google+ 应用中使用的网格状布局的名称是什么?

android - 待定 Intent 立即触发

android - 使用全屏隐藏 android 4.4+ 或 kitkat 中的状态栏

android - 如何删除操作栏和 Activity 布局之间的这个 "line"