下载完成的意图操作在AndroidManifest.xml中不可见
我正在尝试注册一个广播接收器,它监听“android.intent.action.DOWNLOAD\u COMPLETE”。但它在AndroidManifest.xml中不可见。请帮助你,你可以这样做下载完成的意图操作在AndroidManifest.xml中不可见,android,intentfilter,android-broadcastreceiver,android-download-manager,Android,Intentfilter,Android Broadcastreceiver,Android Download Manager,我正在尝试注册一个广播接收器,它监听“android.intent.action.DOWNLOAD\u COMPLETE”。但它在AndroidManifest.xml中不可见。请帮助你,你可以这样做 DownloadManager downloadManager; downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE); Uri uri = Uri.parse("http
DownloadManager downloadManager;
downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE);
Uri uri = Uri.parse("http://xxx.apk");
DownloadManager.Request request = new DownloadManager.Request(uri);
// You can choose network type
request.setAllowedNetworkTypes(DownloadManager.Request.NETWORK_WIFI);
downloadManager.getRecommendedMaxBytesOverMobile(getApplicationContext());
final long flag = downloadManager.enqueue(request);
IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE );
BroadcastReceiver receiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
long anotherFlag = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID,-1);
if(anotherFlag == flag){
// do something you want to do
}
}
};
registerReceiver(receiver, filter);
谢谢KeLiuyue,但是我正在考虑实现一个类,它实现了broadcastreceiver。为此,我尝试添加,但没有显示action name=“android.intent.action.DOWNLOAD\u COMPLETE”。可能吗?@user3678389是的,你可以这样做。我的方式是动态注册广播接收。你使用的是静态注册广播接收。没关系。@user3678389你可以看看这个