0

这是我的类 GCMIntentService 的代码,当通知到达电话时调用它。我的问题如下:

当手机收到通知时,他会醒来,但之后就再也不会回到待机模式了。

我认为问题在于唤醒锁,但不知道它是什么。

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;

import com.google.android.gcm.GCMBaseIntentService;

public class GCMIntentService extends GCMBaseIntentService{

    public String regIdtoSend = ""; 

    public GCMIntentService(){
        super(Utils.GCMSenderId);
    }

    @Override
    protected void onError(Context context, String regId) {
        // TODO Auto-generated method stub
        Log.e("", "error registration id : "+regId);
    }

    @Override
    protected void onMessage(Context context, Intent intent) {
        // TODO Auto-generated method stub
        handleMessage(context, intent);
    }

    @Override
    protected void onRegistered(Context context, String regId) {
        // TODO Auto-generated method stub
        // Log.e("", "registration id : "+regId);
        handleRegistration(context, regId);
    }

    @Override
    protected void onUnregistered(Context context, String regId) {
        // TODO Auto-generated method stub

    }

    @SuppressWarnings({ "deprecation", "static-access" })
    private void handleMessage(Context context, Intent intent) {
        // TODO Auto-generated method stub
        Utils.notiMsg = intent.getStringExtra("message");
        Utils.notiTitle = intent.getStringExtra("title");
        Utils.notiType = intent.getStringExtra("type");
        Utils.notiUrl = intent.getStringExtra("url");

        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);

        int icon = R.drawable.ic_action_lab_white;
        CharSequence tickerText = Utils.notiMsg;
        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);
        CharSequence contentTitle = "Nouveau deal";
        CharSequence contentText = Utils.notiMsg;
        Intent notificationIntent = new Intent();
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        mNotificationManager.notify(1, notification);

        Utils.notificationReceived=true;
        PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
        wl.acquire();

    }
}
4

1 回答 1

3

改成

wl.acquire(15000);
wl.acquire();
于 2012-10-14T09:04:14.280 回答