我的应用程序会下载大型的zip文件(100MB+)。我正在使用默认的DownloadManager来进行下载。Google的API文档建议注册一个BroadcastReceiver并监听ACTION_NOTIFICATION_CLICKED事件。我已经这样做了,但是我不知道如何在BroadcastReceiver中调用DownloadManager。
我想要做的基本上就是浏览器所做的事情。当浏览器下载一个文件并且用户点击DownloadManager通知时,DownloadManager窗口将弹出。我该使用哪个intent来实现这一点呢?
我的代码:
<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???
}