单击通知确定应用程序是否已启动的方法

扬·拉贝(Jan Rabe)

有没有一种方法可以通过单击通知或正常启动来确定是否已启动android应用?

普里坦·巴拉(Pritam Baral)

您可以在用于创建通知的PendingIntent的Intent中添加额外的内容。

官方指南

// Instantiate a Builder object.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
// Creates an Intent for the Activity
Intent notifyIntent =
        new Intent(new ComponentName(this, ResultActivity.class));
// Sets the Activity to start in a new, empty task
notifyIntent.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK);
// Creates the PendingIntent
PendingIntent notifyPendingIntent =
        PendingIntent.getActivity(
        this,
        0,
        notifyIntent
        PendingIntent.FLAG_UPDATE_CURRENT
);

// Puts the PendingIntent into the notification builder
builder.setContentIntent(notifyPendingIntent);
// Notifications are issued by sending them to the
// NotificationManager system service.
NotificationManager mNotificationManager =
    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// Builds an anonymous Notification object from the builder, and
// passes it to the NotificationManager
mNotificationManager.notify(id, builder.build());

只需添加 notifyIntent.putExtra("fromNotification", true);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

通过推送通知检测应用程序是否已启动/打开

可以确定是否已回购应用程序?

应用程序无法正确启动(0xC0000056)。单击确定关闭应用程序

如何通过在didFinishLaunchingWithOptions方法中单击通用链接来检查应用程序是否已打开

单击应用程序图标直接启动应用程序时,推送通知数据未获取

Android查看应用程序是否已启动/将应用程序置于前台

确定用户是否已启用应用程序的Safari内容阻止程序扩展

如何确定Windows应用程序是否在Windows启动时自动启动?

如何通知Android应用程序电子邮件验证链接已单击?

单击通知后打开应用程序

应用程序开发人员可以从通知中启动我的活动(已导出)吗?

从通知问题启动应用程序

Android通知持续启动应用程序

如何通过单击推送通知来启动PWA(渐进式Web应用程序)打开?

Android 应用程序未在 Com.onesignal 通知中启动单击

单击时,Android Firebase推送通知会重新启动应用程序

当我单击通知时,我想继续应用程序,而不是启动意图

从 GCM 通知消息确定是否打开了 android 应用程序

确定是否在闪亮的应用程序中单击了DT数据表

检测在未启动应用程序且用户未通过它们打开应用程序时是否收到推送通知

是否有更好的方法从控制台应用程序启动UWP应用程序

如何确定控制台应用程序是否从控制台窗口中启动?

单击带有附加功能的Android通知以初始化应用程序或更新数据:以前的通知启动应用程序时未处理

使用 bash 检查 node.js 应用程序是否已正确启动

检查进程是否已关闭/未运行,然后重新启动应用程序

重新启动应用程序后,NEVPNManager检查是否已连接?

如何识别是否已启动任何应用程序exe?

在应用程序启动期间,我们是否应该每次都注册iOS推送通知?

是否可以从我的应用程序启动网络浏览器,并返回单击的URL?