Android Oエミュレータを使用していて、Firebaseコンソールから通知を受けたい場合は、Android Oを除くすべてのデバイスで正常に動作しています。このエラーがログに記録されます。Androidベースで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ヘルプからの通知を受け取ることができません。
何らかの理由でdownvotingされていますか? –
メッセージが受信されたことを示す 'From:'ログメッセージが表示されますか? –
アプリがフォアグラウンドにあるとき、私はそれを見ることができます。アプリがバックグラウンドに移行した後、エラー@ BobSnyder –