lundi 7 avril 2014

Android Airplane Mode - versions différentes API - Stack Overflow


Can somebody tell me how to handle this situation. I am aware that with API 17, testing for airplane mode has been moved from Setting.System to Settings.Global. Knowing that many of the users will be on phones using the older api, but wanting to handle the deprecation correctly, I've written the following method:


@SuppressWarnings("deprecation")
public static boolean isAirplaneModeOn(Context context) {

try {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
} catch (Exception e) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}
}

The problem is that in my manifest, I've set the minSDK value to 9, which is where I want it. The conflict is that then I get this error:


Call requires API level 17 (current min is 9)


What is the correct way to handle this type of situation? Thanks!




check which version the user has


if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLYBEAN){

}else{

}

then just suppress the lint error



Can somebody tell me how to handle this situation. I am aware that with API 17, testing for airplane mode has been moved from Setting.System to Settings.Global. Knowing that many of the users will be on phones using the older api, but wanting to handle the deprecation correctly, I've written the following method:


@SuppressWarnings("deprecation")
public static boolean isAirplaneModeOn(Context context) {

try {
return Settings.Global.getInt(context.getContentResolver(),
Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
} catch (Exception e) {
return Settings.System.getInt(context.getContentResolver(),
Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}
}

The problem is that in my manifest, I've set the minSDK value to 9, which is where I want it. The conflict is that then I get this error:


Call requires API level 17 (current min is 9)


What is the correct way to handle this type of situation? Thanks!



check which version the user has


if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLYBEAN){

}else{

}

then just suppress the lint error


0 commentaires:

Enregistrer un commentaire