通过点击系统通知栏移除 通知只需要一个方法
Notification notification = new Notification();
notification.setAutoCancel(true);

下面是整个系统弹窗的方法已做了6.0设配
/**
* 头部系统消息提示
* 状态栏提示消息
*/
private void setNotificationDemoForAndroidO(int progress, String content, Context context) {
//ID
String id = “testNotification”;
//名称
String name = “notification”;

    NotificationManager notificationManager = (NotificationManager) context.getSystemService            (NOTIFICATION_SERVICE);    Notification.Builder mBuilder = new Notification.Builder(context);    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.layout_notification);    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {        NotificationChannel channel = new NotificationChannel(id, name, NotificationManager                .IMPORTANCE_DEFAULT);//FLAG_AUTO_CANCEL        mBuilder.setChannelId(id);        notificationManager.createNotificationChannel(channel);        mBuilder.setSmallIcon(R.drawable.logo);

// if (CGlobalData.ifOpenTest != true) {
// Intent intent = new Intent(context, SystemMessagesActivity.class);
// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// mBuilder.setContentIntent(pendingIntent);

        Intent intent= new Intent();        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);        mBuilder.setAutoCancel(true);//点击通知栏移除通知        mBuilder.setContentIntent(pendingIntent);

// EventBus.getDefault().post(new SystemMessageClose(“finish”));//关闭
// }
mBuilder.setContent(remoteViews);
if (progress == 1) {
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
}
remoteViews.setImageViewResource(R.id.iv_notification_image, R.drawable.logo);
remoteViews.setTextViewText(R.id.tv_notification_title, “”);
remoteViews.setTextViewText(R.id.tv_notification_content, content);
remoteViews.setProgressBar(R.id.pBar, 10, progress, false);
remoteViews.setTextViewText(R.id.proNum, progress + “/10”);
} else {
mBuilder.setSmallIcon(R.drawable.logo);
// if (CGlobalData.ifOpenTest != true) {
// EventBus.getDefault().post(new SystemMessageClose(“finish”));//关闭
// Intent intent = new Intent(context, SystemMessagesActivity.class);
// PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// mBuilder.setContentIntent(pendingIntent);

        Intent intent= new Intent();        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);        mBuilder.setAutoCancel(true);//点击通知栏移除通知        mBuilder.setContentIntent(pendingIntent);            mBuilder.setAutoCancel(true);//点击通知栏移除通知

// }
// SystemMessagesCallBack.doCallBackMethod();

// EventBus.getDefault().post(new BaseEvent(“SystemMessages”));
mBuilder.setContent(remoteViews);
if (progress == 1) {
mBuilder.setDefaults(Notification.DEFAULT_SOUND);
}
remoteViews.setImageViewResource(R.id.iv_notification_image, R.drawable.logo);
remoteViews.setTextViewText(R.id.tv_notification_title, “”);
remoteViews.setTextViewText(R.id.tv_notification_content, content);
remoteViews.setProgressBar(R.id.pBar, 10, progress, false);
remoteViews.setTextViewText(R.id.proNum, progress + “/10”);
}
// notificationManager.notify(10, mBuilder.build());
notificationManager.notify(1, mBuilder.build());

}

更多相关文章

  1. Nginx系列教程(六)| 手把手教你搭建 LNMP 架构并部署天空网络电影
  2. Android通知及receiver
  3. 整理Android(安卓)显示系统相关文章及链接
  4. Android之关于onSaveInstanceState和onRestoreInstanceState触发
  5. android 调用系统相机拍照,并保存到SD卡
  6. NSF方式挂载Android分区
  7. Android系统相关备忘
  8. Android(安卓)各个版本WebView
  9. 解决android模拟器上不了网的问题

随机推荐

  1. android gradle编译 多个flavor中加载不
  2. 在Android上使用XML
  3. Android等宽字体
  4. android系统长按的定义
  5. android 实现区域截图
  6. Android实现图片缩放与旋转
  7. android 设置主题
  8. loading android
  9. android 写文件权限
  10. Android TextView滚动