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());
热门推荐
7 入学校简短祝福语
10 结婚祝福语简短精辟横幅
11 企业跨年元旦祝福语简短
12 公司年终晚会祝福语简短
13 新年给父亲简短祝福语
14 中考物理加油祝福语简短
15 小寒健康祝福语大全简短
16 韩语妹妹生日祝福语简短
17 下雪路滑祝福语简短
18 如何问候生日祝福语简短