다음과 같이 PHP를 사용하여 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 알림 같은 설정 에서이 응용 프로그램을 중지 강제로 심지어 모든 시나리오를 보여주고있다)2. "OnMessageReceived"이러한 메시지, 본문 내용을 내 활동/파편에 전달하는 방법 알림을 받습니까?
3. 모든 토큰을 배열에 추가하는 대신 모든 사람에게 알림을 보내려합니다. 그런 식으로 "모두에게 보내기"와 같이 처리 할 수있는 다른 방법은 없습니까?
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 롤리팝)
- 화웨이 명예 5C (5.1.1 롤리팝)
성공한 장치 : (최근 트레이에서 제거한 후에 알림이 전송 됨)
(210)- HTC 한 X (4.2 젤리 빈)
- 삼성 은하 그랜드 프라임 (4.4 Kitkat으로)
OS 버전 (Lollipop vs Jelly Bean 등)의 문제라고 생각하지 않습니다. Google Play 서비스가 수신자에게서 해산 된 앱을 깨울 수 있는지 여부는 문제가 될 가능성이 큽니다. 일부 제조업체에서는이 동작을 조정합니다. FCM 팀이 예상대로 작동하지 않는 장치를 더 깊이 볼 수 있도록 firebase 지원 문제를 제기하는 것이 좋습니다. https://firebase.google.com/support/ –
데이터 메시지에도 동일한 문제가 있습니다. 그리고 내가 말할 수있는 한, 안드로이드의 어떤 버전에서도 작동하지 않습니다. 마시멜로와 롤리팝에 대한 테스트를 마쳤습니다. – rGun
lava Irish x1 –