小编lin*_*ntu的帖子

屏幕锁定时Android未收到位置更新

我的应用必须持续跟踪用户.为此,我有一个LocationListener应该连续接收位置更新.问题是当屏幕关闭时,它不会收到任何更新.

我试过添加一个部分唤醒锁:

mLocationRequest = LocationRequest.create();
        mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS);
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS);
        mLocationClient = new LocationClient(ADS.getAppContext(), new LocationGatherer(), new LocationGatherer());
        mLocationClient.connect();
        PowerManager pm = (PowerManager) ADS.getAppContext().getSystemService(Context.POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
        wl.acquire();
Run Code Online (Sandbox Code Playgroud)

但它仍然没有收到更新.

android locationlistener wakelock google-play-services

9
推荐指数
1
解决办法
1693
查看次数

GcmIntentService中的onHandleIntent未被调用

我正在关注Android开发人员的GCM演示.得到以下情况.我没有调用GCMIntentService中的OnHandleIntent.有人可以帮忙吗?

package com.xyz.ads;


import com.google.android.gms.gcm.GoogleCloudMessaging;

import android.app.IntentService;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class GcmIntentService extends IntentService {
    public GcmIntentService() {
        super("GcmIntentService");
        //super.onCreate();
        //super.onHandleIntent();
    }

    public void onCreate() {
        super.onCreate();

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        super.onStartCommand(intent, startId, startId);
        Log.i("LocalService", "Received start id " + startId + ": " + intent);

        return START_STICKY;
    }
    public static final String TAG = "GCM Demo";

    @Override
    protected  void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        GoogleCloudMessaging gcm …
Run Code Online (Sandbox Code Playgroud)

android intentservice

1
推荐指数
1
解决办法
4115
查看次数