简体   繁体   English

Android飞行模式-不同的API版本

[英]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 . 我知道,使用API​​ 17,飞行模式的测试已从Setting.System移至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: 知道许多用户将使用较旧的api在手机上,但是想要正确处理弃用,我编写了以下方法:

@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. 问题是在清单中,我将minSDK值设置为9,这是我想要的值。 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 然后抑制皮棉错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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