私はfcmでヘッドアップ通知を実装しました。 アプリがfcm通知を受け取ると、アプリが実行されていると、画面上にヘッドアップ通知が表示されます。それは良い。アプリが実行されていないとヘッドアップ通知が表示されない理由
私のアプリがバックグラウンドであるか殺されている場合、ヘッドアップ通知は表示されません。 この問題を解決するにはどうすればよいですか? (たぶん私はFCM通知を受信したときに私のアプリが実行されている場合、MyFirebaseMessagingServiceはいい仕事だと思う。しかし、私のアプリがバックグラウンドまたは殺されている場合は、MyFirebaseMessagingServiceクラスは動作しません)
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Map<String, String> data = remoteMessage.getData();
sendNotification(remoteMessage);
}
private void sendNotification(RemoteMessage message) {
Intent push = new Intent(this, SplashActivity.class);
push.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_CLEAR_TASK
| Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, push, PendingIntent.FLAG_CANCEL_CURRENT);
NotificationCompat.Builder builder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setContentTitle("test")
.setContentText(message.getNotification().getBody())
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setVibrate(new long[] {0})
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(fullScreenPendingIntent);
NotificationManager nm =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, builder.build());
}
}
私の問題は自分の間違いではないということですか? – Dennis
はい、リンクを確認してください。いくつかのアイデアを得ることができます。 – Thirumalvalavan
ありがとうございます。私はあなたが天使だと思う – Dennis