gpt4 book ai didi

android - 通知未在 android 中启动 Activity

转载 作者:太空宇宙 更新时间:2023-11-03 13:01:16 27 4
gpt4 key购买 nike

我正在开发一个小应用程序,我希望后台服务在其中发送通知,当用户单击通知时,它必须启动相应的 Activity 。我在这里发布通知代码,我的问题是通知显示在状态栏上,但是当我单击它时它不会启动 Activity 。有人可以建议我哪里出错了。请帮忙。

NotificationManager notificationManager = (NotificationManager) 
getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
"A New Message!", System.currentTimeMillis());
Intent notificationIntent = new Intent(NotificationService.this,
com.jeris.android.MetroActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent
.getService(NotificationService.this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(NotificationService.this, "Bullion",
"Rates for "+ parsedDate+"has not been updated. Go to app to check rates",
pendingIntent);
notificationManager.notify(11, notification);

最佳答案

替换PendingIntent.getService(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

PendingIntent.getActivity(NotificationService.this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

注意 getService 被替换为 getActivity

关于android - 通知未在 android 中启动 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11081414/

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