Android 如何从广播接收器启动下载管理器?
我的应用程序下载大型zip文件(100mb+)。我使用默认的DownloadManager来方便下载。谷歌API文件建议注册一个广播接收器,并监听所点击的操作通知。我正在这样做,但我不知道如何从广播接收器内部调用DownloadManager 我想做的基本上就是浏览器的功能。当浏览器下载文件并且用户单击DownloadManager通知时,DownloadManager窗口弹出。我用什么意图来实现这一点 我的代码:Android 如何从广播接收器启动下载管理器?,android,Android,我的应用程序下载大型zip文件(100mb+)。我使用默认的DownloadManager来方便下载。谷歌API文件建议注册一个广播接收器,并监听所点击的操作通知。我正在这样做,但我不知道如何从广播接收器内部调用DownloadManager 我想做的基本上就是浏览器的功能。当浏览器下载文件并且用户单击DownloadManager通知时,DownloadManager窗口弹出。我用什么意图来实现这一点 我的代码: <receiver android:name="com.test.rece
<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???
}
公共类DownloadReceiver扩展了BroadcastReceiver{
私有静态最终字符串标记=DownloadReceiver.class.getSimpleName();
@凌驾
公共void onReceive(上下文、意图){
String action=intent.getAction();
if(DownloadManager.ACTION\u DOWNLOAD\u COMPLETE.equals(ACTION)){
***用于解压缩的代码已删除***
}
else if(DownloadManager.ACTION\u NOTIFICATION\u CLICKED.equals(ACTION)){
//打开下载管理器
//但是怎么办???
}
找到了我自己的答案。这就成功了
Intent dm = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
dm.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(dm);