我收到GCM通知,但是当我的屏幕被锁定或关闭,然后我的震动和声音不工作。 我试图添加wakelock,但通过GCMListenerService的外观,当触发通知时,已经有一个清醒的意图。 我该怎么做才能使它工作?我失踪的棋子在哪里?
编辑
- 当屏幕打开和解锁我的震动工作。
- 我发现
GcmListenerService
负责部分,用于接收GCM推送通知,它看起来像唤醒锁定是越来越删除(下面的代码)
Bundle var2 = var1.getExtras(); var2.remove("message_type"); var2.remove("android.support.content.wakelockid");
CODE
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification_icon)
.setContentTitle(getString(R.string.new_notification))
.setContentText(body)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setVibrate(new long[] {1000, 1000, 1000})
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = notificationBuilder.build();
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_SOUND;
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wl.acquire(10000);
notificationManager.notify(0, notification);
你加'<使用许可权的android:NAME =“android.permission.VIBRATE” />' –
@Logic是的,当然 – JakubW