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);