Android:通知随记1

来源:互联网 发布:cvr100身份证阅读软件 编辑:程序博客网 时间:2024/05/17 00:52
1)通知的分类
普通通知,大视图通知,进度通知,自定通知
2)获取通知管理者
NotificationManager notificationMananger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
3)创建通知公共的一些参数
公共的一些参数:// 创建视图Builder对象
NotificationCompat.Builder builder = null;builder = new NotificationCompat.Builder(this);// 创建通知Builder对象   // 通知的图片builder.setSmallIcon(R.drawable.qq);   // 设置自动消失builder.setAutoCancel(true);   // 获取声音的UriUri sound = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://"         + getPackageName() + "/" + R.raw.eatthings1);   // 默认的声音// builder.setDefaults(Notification.DEFAULT_VIBRATE |   // Notification.DEFAULT_SOUND);   // 设置自定义通知的声音builder.setSound(sound);builder.setDefaults(Notification.DEFAULT_VIBRATE);   // 获取PendingIntentIntent intent = new Intent(this, Activity00.class);PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent,         PendingIntent.FLAG_ONE_SHOT);   // 设置未来的意图builder.setContentIntent(pIntent);Notification notification = null;
4)普通通知
// 普通通知// 设置标题builder.setContentTitle("花千骨");// 设置内容builder.setContentText("我神的名义诅咒你(白子画):生生世世,不伤,不老,不死");notification = builder.build();notificationMananger.notify(0, notification);
5)大视图通知
NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(            builder);style.setBigContentTitle("大视图通知");// 设置标题for (int i = 0; i < datas.length; i++) {         style.addLine(datas[i]);// 一行一行加到箱子   }      // 创建通知对象notification = builder.build();      // 短信管理者调用通知对象,进行通知notificationMananger.notify(1, notification);
6)进度条通知
builder.setProgress(100, values[0], false);
7)自定通知
// 创建远程的View// packageName:包名RemoteViews remoteViews = new RemoteViews(getPackageName(),            R.layout.view_notification_remote);      // 修改远程ViewremoteViews.setTextViewText(R.id.remote_tv, "中秋节快乐");remoteViews            .setImageViewResource(R.id.remote_image, R.drawable.sina);builder.setContent(remoteViews);notification = builder.build();notificationMananger.notify(3, notification);
8)取消通知
notificationMananger.cancelAll();
     cancel(id);





0 0
原创粉丝点击