有人请帮忙解决它。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张贴您的代码通知..我认为您将该代码写入服务 –