判断系统是否支持 DownloadManager服务

public static boolean isDownloadManagerAvailable(Context context)
    {
        try
        {
            Log.d("Download", "Build.VERSION.SDK_INT is " + Build.VERSION.SDK_INT);
            Log.d("Download", "Build.VERSION_CODES.GINGERBREAD is " + Build.VERSION_CODES.GINGERBREAD);
            if(Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD)
            {              
                return false;
            }
            Log.d("download", "can download");
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.setClassName("com.android.providers.downloads.ui", "com.android.providers.downloads.ui.DownloadList");
            List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            Log.d("Download", "List size is " + list.size());
            return list.size() > 0;
        }
        catch(Exception e)
        {
            return false;
        }
    }

你可能感兴趣的:(download)