我正在使用fcm发送消息。消息到达应用程序,但是当用户单击通知时,它应该打开一个链接,但它只是打开应用程序。我的清单就是这样
<service android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
应该处理通知的地方:
Bundle extras = getIntent().getExtras();
if (extras != null && extras.containsKey("rateUpdate")) {
try {
startActivity(new Intent("android.intent.action.VIEW", Uri.parse("market://details?id=tino.varconn.com.fastnetworks")));
} catch (ActivityNotFoundException unused) {
startActivity(new Intent("android.intent.action.VIEW", Uri.parse("http://play.google.com/store/apps/details?id=tino.varconn.com.fastnetworks")));
}
}
在发送消息时,我总是确保在键值文本框中输入rateUpdate
。我在哪里错了?
答案 0 :(得分:0)
在FirebaseMessagingService类中,您可以从推送通知中获取内容并构建自己的Notification
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
Notification notification = remoteMessage.getNotification()
String title = notification.getTitle()
String body = notification.getBody();
//now you can build and show your own notification
}
使用.setContentIntent()
方法,您可以在其中设置要启动的任何活动。
NotificationCompat.Builder builder = ...
Intent intent = new Intent(context, destinationClass);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent,
0);
builder.setContentIntent(contentIntent);