【发布时间】:2017-02-01 22:14:38
【问题描述】:
我已经按照几个教程将通知从 firebase 发送到 Android 应用程序,并且我能够毫无问题地接收通知。
我想了解两件事:
当用户查看不处理通知的活动时,如何处理接收通知?
当应用程序正在运行但不在前台并且我收到通知时,当我从系统托盘单击它时,应用程序会打开定义了广播者的活动 - 我如何控制哪个活动是打开了吗?
这是处理通知的活动的代码
public class DisplayNotificationActivity extends AppCompatActivity {
private BroadcastReceiver mRegistrationBroadcastReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_notification);
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);
} else if (intent.getAction().equals(Config.PUSH_NOTIFICATION)) {
// new push notification is received
String message = intent.getStringExtra("message");
Toast.makeText(getApplicationContext(), "Push notification: " + message, Toast.LENGTH_LONG).show();
txtMessage.setText(message);
}
}
};
如果您需要查看代码的其他部分,请告诉我。
【问题讨论】:
标签: android notifications