简体   繁体   中英

Android Airplane Mode - Different API versions

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM