Android 创建一个简单的通知
示例
本示例说明如何创建一个简单的通知,当用户单击该通知时启动该应用程序。
指定通知的内容:
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher) //通知图标
.setContentTitle("Simple notification") //标题
.setContentText("Hello word") //身体信息
.setAutoCancel(true); //单击时清除通知创建触发点击的意图:
Intent intent = new Intent(this, MainActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); mBuilder.setContentIntent(pi);
最后,构建通知并显示它
NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(0, mBuilder.build());
热门推荐
4 年月日祝福语简短
10 幼儿祝福语大全简短卡片
11 捐款人留言祝福语简短
12 婚礼祝福语简短精辟的
13 三八简短祝福语给婆婆
14 对离岗同事祝福语简短
15 新婚祝福语大全简短精炼
16 女生 节日祝福语简短大气
17 祝女性生日祝福语简短
18 祝福语大全简短赞美同学