1

문제 내 화면이 잠금 또는 해제 후 내 진동과 소리가 작동하지 않습니다 켜져 그러나알림 진동 화면이 잠겨 소리

내가 GCM 알림을 수신하고 있습니다. wakelock을 추가하려고 시도했지만 GCMListenerService의 모양으로 알림이 트리거 될 때 이미 깨어있는 의도가 있습니다. 작동하게하려면 어떻게해야합니까? 누락 된 부분은 어디 있습니까?

편집 화면이 켜져 있고 잠금 해제 할 때 내 진동이 작동

  • .
  • 나는 GCM 푸시 알림을 수신 할 책임이 GcmListenerService의 일부를 발견하고 가동 잠금이 제거지고처럼 (아래 코드)

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); 
+0

<uses-permission android:name="android.permission.WAKE_LOCK" /> 당신이'추가했다 가지고 필요한 경우 <사용 - 권한 안드로이드 : 이름 = "android.permission.VIBRATE"/>' –

+0

@Logic yes, 물론 – JakubW

답변

0

그래서 그것은 밝혀 볼이 잠금 모드에서 사용자 정의 하나의 코드를했습니다 심지어 그래도 playload에서 알림을 만들 때, 당신의 알림이 안드로이드 다음 data payloadnotification payload 포함 된 경우.

가동 잠금이 필요하지 않습니다 - GcmListenerService은 그 자체가 결정됩니다 그것만큼 당신이

0

당신이 필요 보인다 이 플래그를 서버 측 코드에 delay_while_idle=true 추가하십시오. 는 here

+0

게시 한 링크에 따르면 장치에서 데이터를받지 못한 경우이 플래그가 필요합니다. 제 경우에는 통지와 모든 데이터를받습니다. 유일한 문제는 소리와 진동이 유발되지 않는다는 것입니다. – JakubW

+0

예 기기가 절전 모드이거나 잠금 해제되어있을 때 알림을받지 못했다는 의미입니다. 나는 서버 측에서 delay_while_idle = false를 설정하고 이제는 내 경우에 예상대로 작동합니다. – Meenaxi