私はアンドロイドのプロジェクトでFCMを使用していますが、アプリの実行中に問題なく動作しています。しかし、アプリケーションが殺されるか閉じたときにonReiveMessageは呼び出されません。私はまだデータのプレーロードだけを使用してメッセージを送信しようとしましたが、まだ動作していません。何か解決策はありますか?事前に感謝FCMの背景通知の問題android
1
A
答えて
0
あなたの問題を解決するこのコードを試してください。 MyFirebaseMessagingService.java
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// If the application is in the foreground handle both data and notification messages here.
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Title: " + remoteMessage.getNotification().getTitle());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
sendNotification("", "");
}
// [END receive_message]
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String xyz, String abc) {
Intent intent = new Intent(this, MainActivity.class);
Bundle b = new Bundle();
b.putString("key", xyz);
b.putString("key", abc);
intent.putExtras(b);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("title")
.setContentText("body")
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
boolean useSilhouette = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
if (useSilhouette) {
try {
notificationBuilder.setSmallIcon(R.mipmap.ic_sillate);
} catch (Exception e) {
notificationBuilder.setSmallIcon(R.mipmap.ic_sillate);
}
} else {
notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
}
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//Random id number for notification
Random random = new Random();
int m = random.nextInt(9999 - 1000) + 1000;
notificationManager.notify(m/* ID of notification */, notificationBuilder.build());
}
}
MainActivityにgetIntent()
を経由して値を取得し、あなたがやりたい;)
+0
' {: "APA91 ... zvmu"、 "データ":{ "msgTitle": "新しいタイトル"、 "メッセージ" } "あなたは通知を持っている" "に"}同じように実装されました。アプリが閉じられても動作しません。 –
+0
質問を編集してコードを投稿してください。 –
関連する問題
- 1. Android FCM通知の問題
- 2. FCM通知の問題 - swift3
- 3. 通知背景位置の問題
- 4. 背景通知:android
- 5. 通知アイコンアプリの背景android
- 6. FCMのXamarin.Forms、iOSの背景通知が表示さdoesntの
- 7. FCM通知に関する問題
- 8. Androidプッシュ通知、fcm
- 9. Android Firebase通知(FCM)
- 10. Android SMS通知の問題
- 11. Android:通知の問題
- 12. 背景通知 - ブラックベリー
- 13. 背景からの通知
- 14. Fcm通知android/IOS nodejs
- 15. MobileFirst 7.1.0 Android FCMプッシュ通知
- 16. Androidボタンの背景の問題
- 17. 背景とレイヤーの問題(Androidスタジオ)
- 18. 背景の問題
- 19. Firebase背景と非アクティブな通知iOSの10でプッシュ通知のためのFCMを使用してiOSの
- 20. Androidプッシュ通知のFCMの制限?
- 21. 背景通知(XCodeを8B6)
- 22. FCMプッシュ通知の問題: - 「エラー」:「未登録」
- 23. MarshmallowのAndroidの通知の問題
- 24. Android開発の通知アイコンの問題
- 25. アンドロイドのFCM通知
- 26. FCM:トラックステータスFCMプッシュ通知
- 27. iOS 5の背景ジオフェンシングの通知?
- 28. デフォルトの通知の背景色
- 29. iOSのスウィフト通知アクションの背景色
- 30. サイクルアニメーションの背景の問題
あなたのコード –
チェックこれを提示してください。私はhttps://www.simplifiedcoding.net/firebase-cloud-messaging-tutorial-android/を実装しています。 –
あなたのコードですか、あなたが紹介したオンライン記事を指していますか? –