1

Android O 에뮬레이터를 사용 중이며 Firebase 콘솔에서 알림을 받고 싶습니다. Android O를 제외한 모든 기기에서 정상적으로 작동합니다. 로그에이 오류가 표시됩니다.Android O에서 Firebase 알림이 작동하지 않습니다

W/Notification: Use of stream types is deprecated for operations other than volume control 
W/Notification: See the documentation of setSound() for what to use instead with android.media.AudioAttributes to qualify your playback use case 

나는 채널 ID를 지정해야한다는 것을 알고 있습니다. 는 지금까지

의 AndroidManifest.xml

 <application 
      android:allowBackup="true" 
      android:icon="@mipmap/ic_launcher" 
      android:label="@string/app_name" 
      android:largeHeap="true" 
      android:roundIcon="@mipmap/ic_launcher_round" 
      android:supportsRtl="true" 
      android:theme="@style/AppTheme"> 

      <meta-data 
       android:name="com.google.firebase.messaging.default_notification_icon" 
       android:resource="@drawable/attach" /> 


      <meta-data 
       android:name="com.google.firebase.messaging.default_notification_color" 
       android:resource="@color/colorAccent" /> 

      <meta-data 
       android:name="com.google.firebase.messaging.default_notification_channel_id" 
       android:value="my_notification_channel" /> 

      <service android:name=".Helper.FirebaseIDService"> 
       <intent-filter> 
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> 
       </intent-filter> 
      </service> 

      <service android:name=".Helper.MyFirebaseMessagingService"> 
       <intent-filter> 
        <action android:name="com.google.firebase.MESSAGING_EVENT" /> 
       </intent-filter> 
      </service> 

     <my all activities...> 

했을 그래서 나는 또한 그래서이 모든 일을 한 후이

public class MyFirebaseMessagingService extends FirebaseMessagingService { 
    private static final String TAG = "FCM Service"; 
    private static final int NOTIFICATION_ID = 1; 
    private static final String NOTIFICATION_CHANNEL_ID = "my_notification_channel"; 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 

     Log.d(TAG, "From: " + remoteMessage.getFrom()); 
     Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); 

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
      NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_DEFAULT); 

      // Configure the notification channel. 
      notificationChannel.setDescription("Channel description"); 
      notificationChannel.enableLights(true); 
      notificationChannel.setLightColor(Color.RED); 
      notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000}); 
      notificationChannel.enableVibration(true); 
      notificationManager.createNotificationChannel(notificationChannel); 
     } 


     NotificationCompat.Builder mBuilder; 
     mBuilder = new NotificationCompat.Builder(getApplicationContext()) 
       .setSmallIcon(R.mipmap.ic_launcher) 
       .setContentTitle("Title") 
       .setContentText(remoteMessage.getNotification().getBody()) 
       .setOngoing(true) 
       .setChannelId(NOTIFICATION_CHANNEL_ID); 

     notificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 
} 
} 

처럼 에 FirebaseMessagingService을 채널 ID를 지정했습니다. 나는 여전히 로그에서 오류 메시지를 받았고 console.Any 도움말에서 알림을받을 수 없습니다.

+0

downvoting 뒤에 어떤 이유? –

+0

메시지가 수신되었다는 것을 나타내는 '보낸 사람 :'로그 메시지가 보입니까? –

+0

앱이 전경에있을 때 나는 그것을 볼 수 있습니다. 앱이 배경으로 돌아간 후에 오류 @ BobSnyder –

답변

1

FCM 메시지에 데이터 페이로드가없고 알림 페이로드 만 있고 앱이 백그라운드에있는 경우 Firebase는 알림을 직접 생성하고 onMessageReceived()을 호출하지 않습니다. 이것은 에 설명되어 있습니다.

Android O의 경우 알림 채널을 만들어야합니다. 매니페스트의 기본 알림 채널을 올바르게 정의하고 있지만 채널이 앱이 백그라운드에있을 때 실행되지 않는 onMessageReceived() 코드로 생성되었습니다.

채널을 생성하는 코드를 알림을 받기 전에 실행할 특정 위치로 옮깁니다.

또한 Firebase Release Notes에 표시된 것처럼 알림 채널에 대한 지원이 버전 10.2.6에 추가되었습니다. 해당 버전 이상으로 빌드해야합니다.