gpt4 book ai didi

android firebase 通知不导航到确切的页面

转载 作者:行者123 更新时间:2023-11-29 19:27:26 26 4
gpt4 key购买 nike

我已经完成了 firebase 通知。我可以在通知栏中获得多个通知。当我按下通知栏中的一个通知图标时,它会重定向到上次收到的屏幕。然后,如果我按下通知栏中的待定图标,则什么也不会发生。这是我的代码

 private void sendNotification(Map<String, String> data) {
Intent intent = null;
String messageBody = data.get("Message");
String referenceKey = data.get("ReferenceKey");
String referenceValueFromFCM = data.get("ReferenceValue");

if (LocalRepository.getInstance().isAuthenticated()) {
PromotionData promotionData = new PromotionData();

if (!TextUtils.isEmpty(referenceValue) && TextUtils.isDigitsOnly(referenceValue)) {
promotionData.promotionId = Integer.parseInt(referenceValue);

}
intent.putExtra("key", referenceKey);
intent.putExtra("data", promotionData);
intent.putExtra("value", referenceValue);
intent = new Intent(this, DashboardActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_UPDATE_CURRENT);

long[] pattern = {250, 250, 250, 250, 250};
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getString(R.string.app_name))
.setContentText(messageBody)
.setAutoCancel(true)
.setVibrate(pattern)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);

NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(AppUtil.getNotificationId() /* ID of notification */, notificationBuilder.build());

这是我的 list

 <activity
android:name=".views.dashboard.DashboardActivity"
android:screenOrientation="portrait"
android:exported="true"
android:theme="@style/AppTheme.NoActionBar"
android:windowSoftInputMode="stateAlwaysHidden" />

这是仪表板导航 Activity

 String key = getIntent().getStringExtra("key");
String promotionID = getIntent().getStringExtra("value");
PromotionData promotionData = getIntent().getParcelableExtra("data");

if (!TextUtils.isEmpty(promotionID) && (!TextUtils.isEmpty(key))) {
Intent intent = null;
switch (key) {
case Repository.ModuleCode.WHATS_NEWS:
if (hasPromotionId) {
whatsNew();
intent = new Intent(this, WhatsNewDetailActivity.class);
intent.putExtra("data", promotionData);
intent.putExtra("pushID", pushID);
startActivity(intent);
}else{
whatsNew(); // this is fragment
}
break;

case Repository.ModuleCode.PROMOTION:
if (hasPromotionId) {
promotion();
intent = new Intent(this, PromotionDetailActivity.class);
intent.putExtra("data", promotionData);
intent.putExtra("pushID", pushID);
startActivity(intent);
}else{
promotion(); // this is fragment
}
break;

你能告诉我吗提前致谢。

最佳答案

您可以使用此答案了解如何使用 NotificationActivity 上传递值。 Here's a link which might be helpful

只有你必须像这样用 Intent 传递值,

Intent intent = new Intent(this, yourActivityClass.class);
intent.putExtra("msg",messageBody);

关于android firebase 通知不导航到确切的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40992190/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com