首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

判断系统是不是支持 DownloadManager服务

2013-03-21 
判断系统是否支持 DownloadManager服务public static boolean isDownloadManagerAvailable(Context contex

判断系统是否支持 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;
        }
    }

热点排行