i use android.app.DownloadManager to download some files. but if the phone do not start the download service, the app will crash. i try to write some code to judge if download service is available:
public static boolean isServiceRunning(Context mContext) {
boolean isRunning = true ;
int state = mContext.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
isRunning = false;
}
return isRunning;
}
but this piece of code does not work. it return false on my phone while download service is available. any one any ideas?
0 comments:
Post a Comment