有人請幫忙解決它。Android FCM推送通知,如何處理後臺事件
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// checking for type intent filter
if (intent.getAction().equals(Config.REGISTRATION_COMPLETE)) {
// gcm successfully registered
// now subscribe to `global` topic to receive app wide notifications
FirebaseMessaging.getInstance().subscribeToTopic(Config.TOPIC_GLOBAL);
displayFirebaseRegId();
System.out.println("If condition :" + Config.REGISTRATION_COMPLETE + "::" + Config.PUSH_NOTIFICATION);
} else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
// new push notification is received
String message = intent.getStringExtra("message");
showAlertDialog(MainActivity.this, "Alert", message, true);
txtMessage.setTextColor(Color.GREEN);
Picasso.with(context).load(message).into(iImageView);
// txtMessage.setText(message);
System.out.println("Else condition :" + Config.REGISTRATION_COMPLETE + "::" + Config.PUSH_NOTIFICATION);
}
}
};
這是寫在主要活動的代碼,如果應用程序是在前景不言而喻否則,如果一部分,如果應用程序在後臺運行,它甚至不進入onBroadcastReceiver方法,那麼如何才能我處理背景事件?
什麼公頃你到目前爲止取得了什麼? –
得到了一個演示,能夠發送消息從firebase網站,並在應用程序接收,希望趕上其背景事件,當我點擊通知,我想提出消息在活動 – Developer
PLZ張貼您的代碼通知..我認爲您將該代碼寫入服務 –