をすることができます使用しています。
あなたは
handleIntent機能を無効にする必要があります。
この機能はバックグラウンドでFirebase通知を処理します。その内部で、プッシュメッセージで送信されたすべてのデータをプッシュ通知にします。メッセージから情報を抽出することを忘れないでください。タイトルや本文などの既定のスペースを使用できますが、カスタムデータを送信することもできます。
次は、どのように動作するかのサンプルコードを添付します。
注:この方法を持っていないならば、あなたはどんな質問をして、私はマイルの答えを編集しますを持っている場合は10.0.1
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// TODO: Handle FCM messages here.
// 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.
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody());
}
@Override
public void handleIntent(Intent intent) {
//super.handleIntent(intent);
Log.d(TAG,"Handling Intent");
Bundle mBundle = intent.getExtras();
String img = mBundle.getString("imgURL");
String title = mBundle.getString("gcm.notification.title");
String body = mBundle.getString("gcm.notification.body");
mBundle.putInt("promoId",Integer.valueOf(mBundle.getString("promoId")));
Integer id = mBundle.getInt("promoId");
sendNotification(mBundle);
}
private void sendNotification(Bundle mBundle) {
// Create an explicit content Intent that starts the main Activity.
Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
notificationIntent.putExtras(mBundle);
// Construct a task stack.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Add the main Activity to the task stack as the parent.
stackBuilder.addParentStack(MainActivity.class);
// Push the content Intent onto the stack.
stackBuilder.addNextIntent(notificationIntent);
// Get a PendingIntent containing the entire back stack.
PendingIntent notificationPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
// Get a notification builder that's compatible with platform versions >= 4
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
String title = mBundle.getString("gcm.notification.title");
String body = mBundle.getString("gcm.notification.body");
// Define the notification settings.
builder.setSmallIcon(R.mipmap.ic_launcher)
// In a real app, you may want to use a library like Volley
// to decode the Bitmap.
.setLargeIcon(BitmapFactory.decodeResource(getResources(),
R.mipmap.ic_launcher))
.setColor(Color.RED)
.setContentTitle(title)
.setContentText(body)
.setContentIntent(notificationPendingIntent);
// Dismiss notification once the user touches it.
builder.setAutoCancel(true);
// Get an instance of the Notification manager
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Issue the notification
mNotificationManager.notify(0, builder.build());
}
}
よりfirebaseバージョンアップをアップグレードする必要があります。
バックグラウンドでは、直接トリガーされます。メッセージを変更することはできません。サーバー側からの通知ペイロードにメッセージを設定する必要があります。アプリがバックグラウンドにあるときは、メインアクティビティまたはアクションアクティビティからインテントバンドルを使用してペイロードを処理できます。 –
それをチェックアウトする[Firebaseのバックグラウンドでのアプリの通知を処理する方法](http://stackoverflow.com/a/37845174/3536264) –
通知をどこから送信していますか?私は 'Firebase'コンソールかあなたのサーバーを意味しますか? Firebaseから通知を送信している場合は、オプションに進み、通知にデータを追加します。また、サーバーから送信する場合は、表示メッセージを送信しないでください(データメッセージのみを送信する)。 –