4

내 서버에서 데이터 페이로드 알림을 보내고 있습니다. 예를 들면 다음과 같습니다.onMessageReceived in android 백그라운드에서 앱을 실행하면 호출되지 않음

그런 방식으로 모든 이전 Android O 기기에서 앱이 실행 중이 아니더라도 사용자에게 메시지를 보내고 있습니다. Android O 기기에서 앱이 시작되지 않으면 onMessageReceived가 호출되지 않습니다 ...

O에 몇 가지 새로운 규칙이 있습니까? 어떻게 고칠 수 있니? 감사!

UPDATES

이 질문에 알림에 대한 것이 아니라 중포 기지 메시지 srvice에 대한!

은 어쨌든, 안드로이드 O에 대한 chanels도 구현됩니다

val CHANEL_ID = "MY_CHANEL_ID" 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
    val channel = NotificationChannel(CHANEL_ID, "Channel human readable title", NotificationManager.IMPORTANCE_HIGH) 
    (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(channel) 
} 
+0

manifest에 서비스 클래스를 선언하셨습니까 ?? –

+0

. 다른 (사전 O) 기기가이 메시지를 성공적으로 수신했습니다. –

+0

이 문제에 해결책이 있습니까? – dakshbhatt21

답변

0

당신이 그것을 사용하기 전에 알림 채널을 만들어야합니다.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 

     /* Create or update. */ 
     NotificationChannel channel = new NotificationChannel("my_channel_01", 
      "Channel human readable title", 
      NotificationManager.IMPORTANCE_DEFAULT); 
     mNotificationManager.createNotificationChannel(channel); 
    } 

또한 targetSdkVersion이 26 이상인 경우에만 채널을 사용해야합니다.

NotificationCompat.Builder를 사용하는 경우 호환 라이브러리의 베타 버전 https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0-beta2 (compat 빌더에서 setChannelId를 호출 할 수 있어야 함)로 업데이트해야합니다. 이 라이브러리 업데이트 (API 레벨 26), 알림 채널 당신이 통지의 각 유형에 대해 사용자 정의 채널을 만들 수 있습니다에게 안드로이드 8.0부터 14

+0

고마워,하지만 난 이미 구현 된 채널. 여전히 작동하지 않습니다. –

0

에 minSdkLevel을 제기으로

조심하면 표시하려고합니다. 알림 채널은 사용자가 알림을 관리하는 데 도움이되는 통합 시스템을 제공합니다. Android 8.0 (API 수준 26)을 타겟팅 할 때 사용자에게 알림을 표시하려면 하나 이상의 알림 채널을 구현해야합니다. 이 Android 8.0 (API 수준 26)을 타겟팅하지는 않지만 Android 8.0 (API 수준 26)을 실행하는 기기가 기기에서 사용되는 경우 앱은 Android 7.1 (API 수준 25)을 실행하는 기기에서와 동일한 방식으로 과 동일하게 작동합니다. 이하.

https://developer.android.com/guide/topics/ui/notifiers/notifications.html#ManageChannels

샘플 코드 :

 // The id of the channel. 
     String CHANNEL_ID = "my_channel_01"; 
     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(MainActivity.this).setChannel(CHANNEL_ID) 
         .setSmallIcon(R.mipmap.ic_launcher) 
         .setContentTitle("My notification") 
         .setContentText("Hello World!"); 
     // Creates an explicit intent for an Activity in your app 
     Intent resultIntent = new Intent(this, MainActivity.class); 

     // The stack builder object will contain an artificial back stack for the 
     // started Activity. 
     // This ensures that navigating backward from the Activity leads out of 
     // your app to the Home screen. 
     TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
     // Adds the back stack for the Intent (but not the Intent itself) 
     stackBuilder.addParentStack(MainActivity.class); 
     // Adds the Intent that starts the Activity to the top of the stack 
     stackBuilder.addNextIntent(resultIntent); 
     PendingIntent resultPendingIntent = 
       stackBuilder.getPendingIntent(
         0, 
         PendingIntent.FLAG_UPDATE_CURRENT 
       ); 
     mBuilder.setContentIntent(resultPendingIntent); 
     NotificationManager mNotificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

     // mNotificationId is a unique integer your app uses to identify the 
     // notification. For example, to cancel the notification, you can pass its ID 
     // number to NotificationManager.cancel(). 
     mNotificationManager.notify(0, mBuilder.build()); 
+0

죄송합니다. 채널을 이미 구현했지만 작동하지 않는 것을 잊어 버렸습니다. –

0

문제가 내 일 개 플러스 수소 베타처럼 보이는. 내가 전화를 끊고 전화기를 새로 고침하면 괜찮습니다.