今天学习了DownloadManager,我是静态注册了一个广播接收器来接收下载完成的广播,但是网上看的博客等都是动态注册的,如:
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_NOTIFICATION_CLICKED);
但是在Android Manifest中该怎么写action呢,并没有人说,所以我找了一下,把答案写出来,帮助有需要的朋友。
在Android Manifest中:
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>
</intent-filter>
</receiver>
还有要注意的是如果要在onReceiver()中打开另一个Activity,就要在intent中增加Flag
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
如果还有别的问题,可以留言来探讨。