通知栏中的持久服务图标 [英] Persistent service icon in notification bar

查看:22
本文介绍了通知栏中的持久服务图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何使用持久通知图标显示我的服务正在运行.我发现的许多示例只向通知栏发送可关闭消息.我想要一个持久的图标,当你拉下通知栏时,它会显示服务正在运行,你可以点击它打开应用程序来关闭服务.

I am trying to figure out how to show that my service is running with a persistent notification icon. Many examples I've found only send a dismissable message to the notification bar. I wanted a persistent icon that when you pull down the notification bar it shows that the service is running and you can click it to open the app to shut the service down.

任何人都可以向我指出有关如何完成此操作的资源或教程,任何 APK 都可以,但希望使用 4.0 及更高版本.

Can anyone point me to resources or tutorial on how to accomplish this any APK is fine but would like work with 4.0 and greater.

谢谢.

推荐答案

它应该与可关闭消息相同,除非您更改标志.

it should be the same as a dismissable message except you change the Flag.

通知.FLAG_ONGOING_EVENT

Notification.FLAG_ONGOING_EVENT

代替

通知.FLAG_AUTO_CANCEL

Notification.FLAG_AUTO_CANCEL

当点击通知时,您发送的 Intent 就会运行,因此您可以确保 Activity 执行您想要的任何任务.

When a notification is clicked the intent you send is run, so you make sure that Activity does whatever task you want.

private void showRecordingNotification(){
    Notification not = new Notification(R.drawable.icon, "Application started", System.currentTimeMillis());
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, main.class), Notification.FLAG_ONGOING_EVENT);        
    not.flags = Notification.FLAG_ONGOING_EVENT;
    not.setLatestEventInfo(this, "Application Name", "Application Description", contentIntent);
    mNotificationManager.notify(1, not);
}

这篇关于通知栏中的持久服务图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆