调用系统DownloadManager IllegalArgumentException

调用 系统DownloadManager 是抛出如下异常:

IllegalArgumentException: Unknown URL content://downloads/my_downloads
是因为系统的下载服务被停止了:


    /**
     * 检查系统下载服务是否可用
     * @return
     */
    public static boolean checkDownloadManagerEnable() {
        try {
            ApplicationInfo ai = MaibuWatchApplication.getContext().getPackageManager().getApplicationInfo("com.android.providers.downloads",0);
            return ai.enabled;
        } catch (PackageManager.NameNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return false;
    }

若关闭,跳转到应用详情页,让用户打开:

       if (!NetUtils.checkDownloadManagerEnable()){//下载服务被关闭
            Toast.makeText(context,"下载管理器被关闭,请打开",Toast.LENGTH_SHORT).show();
           dissmisInstallDialog();
           final AlertDialogFragment alertDialogFragment=AlertDialogFragment.newInstance("下载错误","下载管理器被停止,请启动","确定");
           alertDialogFragment.setOnConfirmListener(new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                   Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                   Uri uri = Uri.fromParts("package", "com.android.providers.downloads", null);
                   intent.setData(uri);
                   context.startActivity(intent);
                   alertDialogFragment.dismiss();
               }
           });
           alertDialogFragment.show(context.getFragmentManager(),"open");
           return;
       }






你可能感兴趣的:(调用系统DownloadManager IllegalArgumentException)