FCM(Firebase cloud messaging)プッシュ通知を自分のアプリケーションに組み込む際にちょっと混乱します。アプリがバックグラウンドにないときにプッシュ通知サービスが実行されていません
通常、インテントサービスではなく、他のサービスがもう途中で停止しません。私は
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.e(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage == null)
return;
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.e(TAG, "NotificationBean Body: " + remoteMessage.getNotification().getBody());
//This method is responsible for handling notification
handleNotification(remoteMessage.getNotification().getBody());
}
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.e(TAG, "Data Payload: " + remoteMessage.getData().toString());
try {
JSONObject json = new JSONObject(remoteMessage.getData().toString());
handleDataMessage(json);
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
}
}
}
に従うようFirebaseMessagingServiceに拡張することで、サービスの提供を受ける私のメッセージを作成し、次のようにマニフェストにサービスを登録している:このサービスは、アプリは、ライブとで実行されているときに実行される
<service android:name=".service.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
背景も。しかし、アプリがバックグラウンドにないときは、サービスはもう実行されません。
@Override
protected void onResume() {
super.onResume();
// register GCM registration complete receiver
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(Config.REGISTRATION_COMPLETE));
// register new push message receiver
// by doing this, the activity will be notified each time a new message arrives
LocalBroadcastManager.getInstance(this).registerReceiver(mRegistrationBroadcastReceiver,
new IntentFilter(Config.PUSH_NOTIFICATION));
// clear the notification area when the app is opened
NotificationUtils.clearNotifications(getApplicationContext());
}
@Override
protected void onPause() {
super.onPause();
}
は私が私のコードでは何も悪いことを知ってみましょう従うよう
は私が主な活動でサービスを登録しています。 (おそらくそうではありません)。理由は通知がバックグラウンドで実行されていません。どうすればこの問題を克服できますか?
ありがとうございます。
この問題の解決策を見つけました。このソリューションは、Huaweiの携帯電話でうまく機能しています。しかし、Xiomi RedMeのノートには取り組んでいません。3.ソリューションのリンクはhttp://itechify.com/2016/02/01/how-to-fix-missing-push-notifications-on-huawei-smartphones/ – nifCody
できません。プログラムでこの問題を修正しました – nifCody