我的应用程序下载大型zip文件(100mb).我正在使用默认的DownloadManager来方便下载. Google API文档建议注册BroadcastReceiver并收听ACTION_NOTIFICATION_CLICKED.我这样做,但是我不知道如何从BroadcastReceiver中调用DownloadManager.
我想做的是基本上是浏览器.当浏览器下载文件,用户点击DownloadManager通知时弹出DownloadManager窗口.我用什么意图来完成这个?
我的代码:
<receiver android:name="com.test.receiver.DownloadReceiver"> <intent-filter> <action android:name="android.intent.action.DOWNLOAD_COMPLETE"></action> <action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED" /> </intent-filter> </receiver> public class DownloadReceiver extends BroadcastReceiver { private static final String tag = DownloadReceiver.class.getSimpleName(); @Override public void onReceive(Context context,Intent intent) { String action = intent.getAction(); if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(action)) { *** code for unzipping removed *** } else if (DownloadManager.ACTION_NOTIFICATION_CLICKED.equals(action)) { // Open the download manager // BUT HOW??? }
解决方法
找到我自己的答案.这是诀窍.
Intent dm = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); dm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(dm);