以下のようにFirebase通知を自分のwebserviceから送信します。アプリケーションがフォアグラウンドとバックグラウンドで動作しているとき アンドロイドアプリが最近のトレイから削除されたときにFirebase(FCM)通知が届かない
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = SERVER_KEY ',
'Content-Type: application/json'
);
1.Notifications
は何の問題もなく来ている、しかし、私は通知が来ていないその後、最近のトレイからアプリを削除した場合、私はこの本のためのすべてのソリューション処理するために持っている必要がありますか? (Whatsup通知が設定からこのアプリケーションを停止したとしてもすべてのシナリオを表示しています)私は "onMessageReceived"からこれらのメッセージ、ボディコンテンツを私のアクティビティ/フラグメントに渡す方法を通知しましたか?
3.すべてのトークンを配列に追加する代わりに、すべてに通知を送信したい場合もあります。そのようなものを「ALLに送る」のように扱う他の方法はありますか?
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
Log.d(TAG, "Data Payload : " + remoteMessage.getData());
sendNotification(remoteMessage.getData().get("message"));
}
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Firebase Push Notification")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
失敗したデバイス:(最近のトレイから削除した後、通知が来されていません)
- MI Redmi注2(5.0.2ロリポップ)
- Huawei社の名誉5C(5.1.1ロリポップ)
成功デバイス:(最近のトレイから削除した後に通知が来る)
- HTCワンX(4.2ジェリービーン)
- サムスン銀河壮大プライム(4.4キットカット)
これはOSバージョン(Lollipop vs Jelly Beanなど)の問題ではないと思われますが、Google Playサービスが受信者から解雇されたアプリを覚醒させるかどうかはもっと問題になります。一部のメーカーはこの動作を調整します。私は、FCMチームが期待どおりに動作していないデバイスをより深く見ることができるように、firebaseサポートの問題を提言することをお勧めします。 https://firebase.google.com/support/ –
私もデータメッセージで同じ問題を抱えています。そして、私が知る限り、Androidのどのバージョンでも動作していません。私はマシュマロとロリポップでテストしました。 – rGun
lava Irish x1 –