Android开发之文件下载,状态时显示下载进度,点击自动安装
Notification 通知的应用
2者之间传送文件也可以用这个来做
可以给Notification定制一个XML布局
private Notification mDownNotification;
private RemoteViews mContentView; // 下载进度View
private PendingIntent mDownPendingIntent;
public void initDownNotification() {
mDownNotification = new Notification(
android.R.drawable.stat_sys_download, "",
System.currentTimeMillis());
mDownNotification.flags = Notification.FLAG_ONGOING_EVENT;
mDownNotification.flags = Notification.FLAG_AUTO_CANCEL;
mContentView = new RemoteViews(FrCall.getContext().getPackageName(),
R.layout.notification_transfer);
mContentView.setImageViewResource(R.id.downLoadIcon,
android.R.drawable.stat_sys_download);
mDownPendingIntent = PendingIntent.getActivity(FrCall.getContext(), 0,
new Intent(), 0);
}
public void updateDownNotification(int id, int progress) {
// 下载进度发生改变,则发送Message
String title = FrCall.getContext().getString(id);
mContentView.setTextViewText(R.id.downLoadTitle, title);
mContentView.setTextViewText(R.id.progressPercent, progress + "%");
mContentView.setProgressBar(R.id.downLoadProgress, 100, progress, false);
mDownNotification.contentView = mContentView;
mDownNotification.contentIntent = mDownPendingIntent;
mDownNotification.tickerText = title;
mNotifManager.notify(R.id.downLoadIcon, mDownNotification);
}
updateDownNotification只在progress变化的时候调用