Android 용 푸시 알림에 Firebase를 사용하려고합니다. 그러나 나는 매우 이상한 문제에 직면했다. 포 그라운드에서 밀어 넣기를하면 모두 괜찮아요. 전경으로 돌아와 배경으로 돌아갈 때까지 배경으로 밀어 넣기 (데이터 만 전송)를 보내면 모두 OK입니다.두 번째 배경 후에 FirebaseMessagingService가 호출되지 않음
내 FirebaseMessagingService
은 내 앱을 배경으로 두 번째로 호출 할 때 호출되지 않습니다. 또한 Android 에뮬레이터를 사용하고 있습니다. 코드 :
public class MyAndroidFirebaseMsgService extends FirebaseMessagingService {
private static final String TAG = "MyAndroidFCMService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
}
}
//...
public class MyAndroidFirebaseInstanceIdService extends FirebaseInstanceIdService {
private static final String TAG = "MyAndroidFCMIIDService";
@Override
public void onTokenRefresh() {
//Get hold of the registration token
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
//Log the token
Log.d(TAG, "Refreshed token: " + refreshedToken);
}
private void sendRegistrationToServer(String token) {
//Implement this method if you want to store the token on your server
}
}
의 AndroidManifest.xml :
<service android:name=".MyAndroidFirebaseMsgService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service android:name=".MyAndroidFirebaseInstanceIdService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
서버 :
이내가 그것을 어떻게
curl -H "Content-type: application/json" -H "Authorization:key=<MYKEY>" -X POST -d '{"to": "<MYTOKEN>","data": {"hello": "This is a Firebase Cloud Messaging Device Group Message!"}}' https://fcm.googleapis.com/fcm/send
을 를 해결할 수 ?
FirebaseMessagingService 배경 –
경우에 호출하지 않습니다 알림 메시지에 대한 자세한 내용은
(.! getIntent() getExtras() = NULL) {(문자열 키 :.. getIntent() getExtras() keySet 반환 ()) { Object value = getIntent(). getExtras(). get (key); Log.d ("MainActivity :", "키 :"+ 키 + "값 :"+ 값); } } –인 텐트 오브젝트에서 데이터를 가져올 수 있습니다. –