android 点击通知栏消息,无法启动应用程序

android 点击通知栏消息,无法启动应用程序,第1张

appIntentsetAction(IntentACTION_MAIN);

appIntentaddCategory(IntentCATEGORY_LAUNCHER);

action 和 category 在清单文件里面已经定义了,没必要写了吧?

android通知栏点击通知跳转到应用程序,可以在接收通知的方法中,写一个intent,将该应用的主程序类写入参数中,就可以启动,代码如下:

// 创建一个NotificationManager的引用

NotificationManager notificationManager = (NotificationManager)

thisgetSystemService(androidcontentContextNOTIFICATION_SERVICE);

// 定义Notification的各种属性

Notification notification =new Notification(Rdrawableicon,

"督导系统", SystemcurrentTimeMillis());

//FLAG_AUTO_CANCEL 该通知能被状态栏的清除按钮给清除掉

//FLAG_NO_CLEAR 该通知不能被状态栏的清除按钮给清除掉

//FLAG_ONGOING_EVENT 通知放置在正在运行

//FLAG_INSISTENT 是否一直进行,比如音乐一直播放,知道用户响应

notificationflags |= NotificationFLAG_ONGOING_EVENT; // 将此通知放到通知栏的"Ongoing"即"正在运行"组中

notificationflags |= NotificationFLAG_NO_CLEAR; // 表明在点击了通知栏中的"清除通知"后,此通知不清除,经常与FLAG_ONGOING_EVENT一起使用

notificationflags |= NotificationFLAG_SHOW_LIGHTS;

//DEFAULT_ALL 使用所有默认值,比如声音,震动,闪屏等等

//DEFAULT_LIGHTS 使用默认闪光提示

//DEFAULT_SOUNDS 使用默认提示声音

//DEFAULT_VIBRATE 使用默认手机震动,需加上<uses-permission android:name="androidpermissionVIBRATE" />权限

notificationdefaults = NotificationDEFAULT_LIGHTS;

//叠加效果常量

//notificationdefaults=NotificationDEFAULT_LIGHTS|NotificationDEFAULT_SOUND;

notificationledARGB = ColorBLUE;

notificationledOnMS =5000; //闪光时间,毫秒

// 设置通知的事件消息

CharSequence contentTitle ="督导系统标题"; // 通知栏标题

CharSequence contentText ="督导系统内容"; // 通知栏内容

Intent notificationIntent =new Intent(MainActivitythis, MainActivityclass); // 点击该通知后要跳转的Activity

PendingIntent contentItent = PendingIntentgetActivity(this, 0, notificationIntent, 0);

notificationsetLatestEventInfo(this, contentTitle, contentText, contentItent);

// 把Notification传递给NotificationManager

notificationManagernotify(0, notification);

id An identifier for this notification unique within your application。帮助讲的很清楚,这个值是你这条通知的应用全局唯一标识。在类里声明这个静态终态常量就行了。

这里的只是权限的管理,系统允不允许你产生通知的控制中心而已。如果只是简单的要产生使用通知栏产生一条消息,你可以参考如下代码(该代码的功能是点击通知栏后跳转某个Activity,里面一些参数根据需要来替换):

Context context = XXX(某个context);

targetIntentsetFlags(IntentFLAG_ACTIVITY_NEW_TASK);

PendingIntent contentIntent = PendingIntentgetActivity(context,

NOTIFICATION_ID,

targetIntent,

PendingIntentFLAG_UPDATE_CURRENT);

NotificationCompatBuilder notifyBuilder = new NotificationCompatBuilder(

context);

notifyBuildersetSmallIcon(Rdrawableic_launcher);

notifyBuildersetContentTitle(title);

notifyBuildersetContentText(content);

notifyBuildersetAutoCancel(true);

notifyBuildersetWhen(SystemcurrentTimeMillis());

notifyBuildersetDefaults(NotificationDEFAULT_ALL);

notifyBuildersetContentIntent(contentIntent);

Notification noti = notifyBuilderbuild();

(NotificationManager) contextgetSystemService(ContextNOTIFICATION_SERVICE))notify(NOTIFICATION_ID, noti);

 0

设置安卓手机通知栏提示音的方法如下。

1、以OPPO手机为例,点击打开手机设置,如图。

2、进入设置页面,下拉菜单找到“声音与振动”选项并点击,如图。

3、进入声音与振动设置页面,如果要将通知栏提示声音设为振动,把“静音时振动”和“静音”两个选项开启就可以了。

4、如果要把通知栏提示音关闭,把“静音时振动”选项关闭,把“静音”选项开启就不会有提示音了。

5、如果需要通知栏有提示音,把以上两个选项关闭就可以了,也就是“静音时振动”和“静音”选项,如图。

service 没有在androidManifestxml 文件中进行注册。

在application下加入

<service android:name="your service package"/>

如果你启动service的intent是隐式的intent 需要在service 写上intent-filter 基本上和你注册activity差不错。

Intent intent = new Intent(activity, DevicelistActivityclass);这句话就是跳转到DevicelistActivity,如果想开启app,只需要跳转到MainActivity,也就是你的根

Activity

notificationflags |= NotificationFLAG_AUTO_CANCEL;

nmnotify(NOTIFY_ID, notification);

以上就是关于android 点击通知栏消息,无法启动应用程序全部的内容,包括:android 点击通知栏消息,无法启动应用程序、android 通知栏如何跳转到应用程序、Android中 m_NotificationManager.notify( 0 , m_Notification) 的第一个参数 0 是什么意思等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10136642.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存