android Download Manager被禁用

来源:互联网 发布:网络词语大全2016 编辑:程序博客网 时间:2024/05/21 13:23

nknown java.lang.IllegalArgumentException: Unknown URL content://downloads/my_downloads

Then later, I figured it out that the reason is because user disabled Android Download Manager. I check if the Download Manager is disabled by checking it's package name with the code below.

int state = this.getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads");

And now, I need to find a way to enable the Download Manager if it is disabled. I tried setting it's enable state with the permission in Manifest but I keep getting Security Exception.

this.getPackageManager().setApplicationEnabledSetting("com.android.providers.downloads", PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>

Check if download manager is available:

   int state = this.getPackageManager().getApplicationEnabledSetting("com.android.providers.downloads");if(state==PackageManager.COMPONENT_ENABLED_STATE_DISABLED||state==PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER||state==PackageManager.COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED){// Cannot download using download manager}            else {                request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);                request.setDescription(fileName);                   manager.enqueue(request);             }

And the solution for trying to enable download manager is:

packageName = "com.android.providers.downloads"try {    //Open the specific App Info page:    Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);    intent.setData(Uri.parse("package:" + packageName));    startActivity(intent);} catch ( ActivityNotFoundException e ) {    //e.printStackTrace();    //Open the generic Apps page:    Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);    startActivity(intent);}

0 0