Notification的例子,请参考附件。
1. 创建Notification builder
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon) // 一个图标
.setContentTitle("My notification") // 标题
.setContentText("Hello World!"); // 具体内容
2. 定义notification action
Intent resultIntent = new Intent(this, ResultActivity.class); // 点击后跳转的activity
...
// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);
3. 设置notification点击的行为
PendingIntent resultPendingIntent;
...
mBuilder.setContentIntent(resultPendingIntent);
4. 启动notification
NotificationCompat.Builder mBuilder;
...
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
5. 取消notification
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.cancel(NOTIFICATION_ID);
分享到:
相关推荐
熟食店 监视电子邮件nofitication应用
打开 黑客马拉松:SAP TechEd 2015,巴塞罗那 演示: : 请记住,您应该具有HANA...使用在Cloud Platform上运行的Nofitication服务自动通知关键区域 有效利用免费的天气预报数据来提高主动性 屏幕截图: 开机管理员主页
1.服务 DownloadService 下载apk 通知栏nofitication显示进度并自动安装 支持静默下载 支持自动安装 点击通知栏安装 2.服务 DownloadService2 用downloadManager进行下载.大家可酌情选择
AppleStore 可用性爬虫 一旦像 iPhone 6 这样的 Apple 产品在特定商店可供...vim config.json # edit config.json file to set up your nofitication preferences sudo pip install tornado python crawler.py 关于 苹
vim config.json # edit config.json file to set up your nofitication preferences sudo pip install -r requirements.txt python crawler.py 关于 和 上的专用服务器价格惊人,但是它们总是缺货。 由于可以购买...