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

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

问题描述

我试图找出如何证明我的服务与永久通知图标运行。很多例子我发现只有发送 dismissable消息以通知栏。我想要一个持久的图标,当你拉下通知栏则说明该服务正在运行,您可以点击它来打开应用程序下来关闭该服务。

任何人都可以点我的资源或教程如何做到这一点的任何APK是不错,但想工作,4.0及更高版本。

感谢。

解决方案

它应该只是更改了国旗是一样的dismissable消息。

Notification.FLAG_ONGOING_EVENT

而不是

Notification.FLAG_AUTO_CANCEL

在通知被点击您发送的意图运行,所以你要确保活动做任何任务你想要的。

 私人无效showRecordingNotification(){
    通知不等于新的通知(R.drawable.icon,应用程序启动,System.currentTimeMillis的());
    PendingIntent contentIntent = PendingIntent.getActivity(此,0,新的意向(这一点,main.class),Notification.FLAG_ONGOING_EVENT);
    not.flags = Notification.FLAG_ONGOING_EVENT;
    not.setLatestEventInfo(这一点,应用程序名,应用说明,contentIntent);
    mNotificationManager.notify(1,没有);
}
 

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.

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.

Thanks.

解决方案

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

Notification.FLAG_ONGOING_EVENT

instead of

Notification.FLAG_AUTO_CANCEL

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天全站免登陆