【发布时间】:2012-11-01 21:41:27
【问题描述】:
下面粘贴的代码显然 (1) 将我的服务设置为前台服务并 (2) 在屏幕顶部的托盘上显示我的图标。如果用户点击我的图标,今天的日期很快就会闪烁——我想这是某种默认行为。 ContentTitle 和 ContentText 从不显示(那么它们有什么用?)
我希望发生的情况是,当点击图标以显示某种下拉菜单或弹出窗口时,允许用户选择取消或结束我的服务。我似乎找不到任何此类功能的示例。这可以做到吗?怎么样?
顺便说一句,我的通知的唯一目的是让我的服务在前台运行。我从不需要通知用户任何事情。
谢谢,加里
NotificationCompat.Builder b = new NotificationCompat.Builder(this);
b.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("PhoneStalker")
.setContentText("Hello World");
Intent WhatIsThisIntentFor = new Intent(Intent.ACTION_VIEW);
b.setContentIntent(PendingIntent.getActivity(this, 0, WhatIsThisIntentFor, 0));
通知 n = b.build();
startForeground(5481, n);
【问题讨论】:
标签: android service notifications