Notification的理解及使用


NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);;

Notification notification = new Notification();//创建一个notification对象

notification.icon = R.drawable.ic_log;//设置通知栏上的图标

notification.flags = Notification.FLAG_ONGOING_EVENT;

notification.tickerText = "开始下载";//设置通知栏上显示的内容

通知的默认参数DEFAULT_SOUND,DEFAULT_VIBRATE,DEFAULT_LIGHTS.

//如果要全部采用默认值,用DEFAULT_ALL.
//此处采用默认声音
notification.defaults=Notification.DEFAULT_SOUND; 

使用自定义视图

remoteViews = new RemoteViews(getPackageName(), R.layout.test);
remoteViews.setImageViewResource(R.id.iv_down_load_icon,
R.drawable.ic_log);//获取自定义视图上的控件并进行设置
remoteViews.setTextViewText(R.id.tv_app_name,
getResources().getString(R.string.app_name));//获取自定义视图上的控件并进行设置
remoteViews.setTextViewText(R.id.tv_download_time,
CommonUtil.formatDateHour());//获取自定义视图上的控件并进行设置
notification.contentView = remoteViews;
Intent intentInstal = new Intent(UpdataService.this, InstallApkBroadcast.class);
intentInstal.putExtra("filepath", APKURL);
// intentInstal.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intentInstal.addCategory(Intent.CATEGORY_DEFAULT);
PendingIntent pi = PendingIntent.getBroadcast(UpdataService.this, 0,//开启一个广播
intentInstal, Intent.FLAG_ACTIVITY_NEW_TASK);
notification.contentIntent = pi;


notificationManager.notify(NOTIFICATION_ID, notification);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值