Android 我想按照我在firebase控制台中设置的值打开链接,如何做到这一点?
我是一个没有太多想法的初学者,现在当我发送通知时,它总是打开启动程序活动,我想根据我设置的值打开不同的链接。请详细说明。谢谢Android 我想按照我在firebase控制台中设置的值打开链接,如何做到这一点?,android,firebase,Android,Firebase,我是一个没有太多想法的初学者,现在当我发送通知时,它总是打开启动程序活动,我想根据我设置的值打开不同的链接。请详细说明。谢谢 public class MyFireBaseMessagingService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { Intent intent = new Intent(this,noti
public class MyFireBaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent intent = new Intent(this,notifications.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
notificationBuilder.setContentTitle("Model Club ");
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setSmallIcon(R.drawable.model);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());//*/
}
In android manifest
<service android:name=".MyFirebaseInstantIdService">
<intent-filter>
<action android:name="com.google.firebase.modelclub.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name=".MyFireBaseMessagingService">
<intent-filter>
<action android:name="com.example.ankitavishek.modelclub.firebase.MESSAGING_ID_EVENT" />
</intent-filter>
</service>
<activity android:name=".notifications"
android:label="Notifications"
android:parentActivityName=".Home">
<intent-filter>
<action android:name="com.example.ankitavishek.modelclub_TARGET_NOTIFICATION" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
公共类MyFireBaseMessagingService扩展了FirebaseMessagingService{
@凌驾
收到消息时公共无效(RemoteMessage RemoteMessage){
Intent Intent=新的Intent(这是notifications.class);
intent.setFlags(intent.FLAG\u ACTIVITY\u CLEAR\u TOP);
PendingEvent PendingEvent=PendingEvent.getActivity(this,0,intent,PendingEvent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder=新建NotificationCompat.Builder(此);
notificationBuilder.setContentTitle(“模型俱乐部”);
notificationBuilder.setContentText(remoteMessage.getNotification().getBody());
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(待定内容);
notificationBuilder.setSmallIcon(R.drawable.model);
NotificationManager NotificationManager=(NotificationManager)getSystemService(Context.NOTIFICATION\u服务);
notificationManager.notify(0,notificationBuilder.build())//*/
}
在android清单中
您还应该发送这样的数据
{
"to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"notification" : {
"body" : "great match!",
"title" : "Portugal vs. Denmark",
"icon" : "myicon"
},
"data" : {
"open": "Name of activity"
}
}
参考:
然后在
MyFireBaseMessagingService$onMessageReceived
挂起的意图不起作用?不同的链接指向URL页面?是不同的URL页面在意图中显示消息并像这样启动意图。您能告诉我如何发送数据吗?(我使用的是firebase)
if(remoteMessage.getData().get("open").equals("MY_ACTIVITY")){
Intent intent = new Intent(this,Activity1.class);
intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
...
}