当我的任务运行时在状态栏中显示图标
我正在创建一个 android 服务,它将在设备启动过程完成后开始运行。在我的服务中,我正在创建一个任务。该任务将根据某些条件随时启动或停止。我的意图是每当我开始任务时,我想在状态栏中显示一个图标,以知道我的任务正在运行,就像蓝牙图标在打开时会显示一样。
I am creating an android service which will start running after the device boot process completed. In my service i am creating a task. This task will be started or stopped at any time depending on some conditions. My intention is whenever i started my task, i want to display an icon in status bar to know that my task is running like bluetooth icon will be displayed when it is turned ON.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要一个通知。代码在说话:)
在您的服务中:
要显示通知:
并隐藏它,您只需执行以下操作:
以下是一些说明:
R.drawable.status_icon
:通知图标R.string .local_service_started
:通知标题R.string.local_service_label
:通知最新信息(子标题)MainActivity.class
:将要执行的 Activity当用户单击通知时启动You need a Notification. Code is talking :)
In your Service:
To show the notification:
and to hide it, you simply do this:
Here are some clarifications:
R.drawable.status_icon
: Notification iconR.string.local_service_started
: Notification titleR.string.local_service_label
: Notification latest info (sub-title)MainActivity.class
: The Activity that will be launched when the user click the notification您可以使用自定义标题栏,例如
带有图像的自定义标题
并检查您的服务启用或禁用的首选项设置并设置自定义标题。但在执行此操作之前,请阅读: http://developer.android.com /guide/topics/ui/notifiers/notifications.html
You can use a Custom title bar like
Custom title with image
And Check the preference setting that your service is enable or disable and set custom title. but before doing this please Read : http://developer.android.com/guide/topics/ui/notifiers/notifications.html