我开发了一个应用程序来下载视频文件并将其存储在SD卡中.在此过程中,我还使用了更新下载的进度和状态作为状态栏通知NotificationManager.
我的班级叫做DownloadTask.java延伸AsyncTask.所以在这里我使用onProgressUpdate()方法更新进度,我在其中使用了NotificationManager该目的.一切都像魅力一样,除了下载完成后我想点击通知打开特定的视频文件.所以这就是我所做的:
mNotificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
int icon = android.R.drawable.stat_sys_download_done;
long when = System.currentTimeMillis();
mNotification = new Notification(icon, "", when);
mContentTitle_complete = mContext.getString(R.string.download_complete);
notificationIntent = new Intent(mContext,OpenDownloadedVideo.class);
notificationIntent.putExtra("fileName", file);
mContentIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);
mNotification.setLatestEventInfo(mContext, file, mContentTitle_complete, mContentIntent);
mNotification.flags = Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(NOTIFICATION_ID, mNotification);
Run Code Online (Sandbox Code Playgroud)
请注意,在我的情况下fileName,它NOTIFICATION_ID是独一无二的.
在Activity OpenDownloadedVideo.java打开的文件:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
fileName = getIntent().getExtras().getString("fileName");
Intent i = new Intent(Intent.ACTION_VIEW);
File …Run Code Online (Sandbox Code Playgroud)