【发布时间】:2012-03-13 00:33:47
【问题描述】:
我的应用程序下载大型 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???
}
【问题讨论】:
标签: android