我正在成功收到通知。但我需要的是当我点击通知时应该移动到某个数据的特定活动。在启动活动时引发空指针异常错误。
Firebase功能: //我的包名是com.google.tho.temp
const token_id = result.val();
const payload = {
notification: {
title: `${from_user_id} id_of my`,
body: `${userName} send order request`,
icon: "default",
sound : "default",
click_action : "com.google.tho.TARGET_NOTIFICATION"
},
data : {
from_user : from_user_id
}
};
清单文件:
<activity
android:name=".Open profile"
android:label="Openpro"
android:parentActivityName=".Received_orders">
<intent-filter>
<action android:name="com.google.tho.TARGET_NOTIFICATION"></action>
<category android:name="android.intent.category.DEFAULT"></category>
</intent-filter>
</activity>
通知接收者类:
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
String noti_title = remoteMessage.getNotification().getTitle();
String noti_message = remoteMessage.getNotification().getBody();
String click_Action = remoteMessage.getNotification().getClickAction();
String from_user_id = remoteMessage.getData().get("from_user").toString();
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo)
.setContentTitle(noti_title)
.setContentText(noti_message);
Intent resultIntent = new Intent(click_Action);
resultIntent.putExtra("signal",from_user_id);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
int mNotificationId = (int) System.currentTimeMillis();
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
打开profile.class:
signal = getIntent().getStringExtra("signal").toString().trim();