我收到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