gpt4 book ai didi

android - 当用户点击通知点击android时如何启动应用程序或置于最前面

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

我正在处理推送通知。当用户单击通知时,我想启动应用程序以防它未启动,或者将其置于最前面以防它已启动。谢谢

最佳答案

这是我在这里找到答案的完整代码 Bring application to front after user clicks on home button

    Intent intent = new Intent(ctx, SplashScreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);

PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT),
PendingIntent.FLAG_CANCEL_CURRENT);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
ctx).setContentTitle(extras.getString("title"))
.setContentText(extras.getString("message"))
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(contentIntent);
Notification noti = mBuilder.build();
noti.flags = Notification.DEFAULT_LIGHTS
| Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(NOTIFICATION_ID, noti);

重要的是 Intent 上的标志,这将打开应用程序或将其置于最前面,如果您在浏览应用程序时单击通知,则不执行任何操作

关于android - 当用户点击通知点击android时如何启动应用程序或置于最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17548658/

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