我想打开一个活动,让我在通知点击时说SplashActivity
,与 click_action 无关。
当前,在收到通知的情况下,我收到 click_action 来处理用户界面,例如
如果用户在个人资料页面上,并且后端团队从管理控制台更新了他的个人资料。
在这种情况下,应用会收到带有 click_action profile_update的通知。应用会检查 click_action 并刷新配置文件页面。
到现在为止,一切都很好,但是当应用程序在后台运行并收到带有 click_action profile_update的通知,并且用户单击通知时-通知将从通知托盘中消失,并且不执行任何导航。
我已声明SplashScreen
,将在单击通知时打开,如下所示:
<activity
android:name=".SplashScreen"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</activity>
仍然没有用户导航到SplashScreen
。
答案 0 :(得分:0)
在创建活动的通知传递意图时
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this, SplashActivity .class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Prayer time")
.setContentText("Its " + salatName + " time.")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pIntent)**Pending intent has the intent of activity you want to open **
.addAction(R.drawable.close,"Dismiss",snoozePendingIntent)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setPriority(NotificationCompat.PRIORITY_DEFAULT);
notificationManager.notify(0, builder.build());
将“活动”的意图传递给您要在单击通知时打开的待定意图