- 为您的接收者使用完整的软件包名称,例如
com.example.DownloadListenerService
- Add
android:exported="true"
BroadcastReceiver
可以outside
从其应用程序的来源接收消息。 - 更改的名称
Action
在intent-filter
以android.intent.action.DOWNLOAD_COMPLETE
<receiver android:name="com.example.DownloadListenerService" android:exported="true" > <intent-filter> <action android:name="android.intent.action.DOWNLOAD_COMPLETE" /> </intent-filter></receiver><uses-permission android:name="android.permission.INTERNET" />
仅当从您的应用程序使用进行注册时,才会触发接收器
registerReceiver(@Nullable BroadcastReceiverreceiver,IntentFilter filter);
要排队的代码下载:
DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);DownloadManager.Request request = new DownloadManager.Request(Uri.parse("https://www.google.com/images/srpr/logo4w.png"));dm.enqueue(request);


