android - Firebase 推送通知 - 如何更改活动目的地?
问题描述
我有一个推送通知,表明视频已成功上传。我想要的是更改单击通知的活动目的地,现在它会转到我的 MainActivity,但我不知道如何更改它。
我有文档中的 FirebaseMessagingService 类,但我不明白我应该把意图放在哪里,因为似乎我从来没有到达过这个地方 -
public class MyFirebaseMessagingService extends FirebaseMessagingService {
public static final String RECEIVED_FCM_ACTION = "com.onemdtalent.app.RECEIVED_FCM_ACTION";
public static final String BD_KEY_BODY = "BD_KEY_BODY";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// [START_EXCLUDE]
// There are two types of messages data messages and notification messages. Data messages are handled
// here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
// traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
// is in the foreground. When the app is in the background an automatically generated notification is displayed.
// When the user taps on the notification they are returned to the app. Messages containing both notification
// and data payloads are treated as notification messages. The Firebase console always sends notification
// messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
// [END_EXCLUDE]
Timber.tag("remoteMessage").d(remoteMessage.getData().toString());
//String image = remoteMessage.getData().get("image");
Timber.d("onMessageReceived: %s", remoteMessage.getFrom());
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
String body = remoteMessage.getNotification().getBody();
Timber.d("Message Notification Body: %s", body);
// broadcast
Intent localIntent = new Intent(RECEIVED_FCM_ACTION);
localIntent.putExtra(BD_KEY_BODY, body);
LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
}
}
解决方案
使用 Pendingintent 设置您的目标活动。
Intent intent = new Intent(this,YourActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
在您的通知构建器中设置这样的内容意图
builder.setContentIntent(pendingIntent);
推荐阅读
- matlab - 使用 Matlab Coder 对字符串元胞数组进行字符串比较
- reactjs - 剪辑路径动态转换以填充容器
- python - axios响应是一个字符串,里面有回车,应该是一个数组
- aws-device-farm - 为什么 Appium python find_element_by_id 在 AWS 设备场中失败但在本地工作?
- github - 创建 github 站点/自定义页面/多个项目
- python - one_shot_iterator,占位符,无法捕获占位符
- c - 如何在不输入命令提示符的情况下将光标移动到下一行?
- c++ - 将一个类的对象声明为另一个类的成员 (C++)
- spring - xwEx 对 log4j2 的含义?
- c# - C#:通过单例类访问类的实例时如何修复 System.TypeInitializationException?