首先我们先 看createNotification().这个方法:
/*** * 创建通知栏 */ RemoteViews contentView; public void createNotification() { notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notification = new Notification(); notification.icon = R.drawable.ic_launcher;// 这个图标必须要设置,不然下面那个RemoteViews不起作用. // 这个参数是通知提示闪出来的值. notification.tickerText = "开始下载"; // // updateIntent = new Intent(this, MainActivity.class); // pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0); // // // 这里面的参数是通知栏view显示的内容 // notification.setLatestEventInfo(this, app_name, "下载:0%", // pendingIntent); // // notificationManager.notify(notification_id, notification); /*** * 在这里我们用自定的view来显示Notification */ contentView = new RemoteViews(getPackageName(), R.layout.notification_item); contentView.setTextViewText(R.id.notificationTitle, "正在下载"); contentView.setTextViewText(R.id.notificationPercent, "0%"); contentView.setProgressBar(R.id.notificationProgress, 100, 0, false); notification.contentView = contentView; updateIntent = new Intent(this, MainActivity.class); updateIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); pendingIntent = PendingIntent.getActivity(this, 0, updateIntent, 0); notification.contentIntent = pendingIntent; notificationManager.notify(notification_id, notification); }上面实现的也不难理解.(主要是初始化Notification,用于提醒用户开始下载)