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

时间:2013-08-09 19:59:32

标签: android api version

有人可以告诉我如何处理这种情况。我知道,对于API 17,飞机模式的测试已从Setting.System移至Settings.Global。知道许多用户将使用旧的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;
    }   
}

问题是在我的清单中,我将minSDK值设置为9,这就是我想要的地方。冲突就是我得到了这个错误:

Call requires API level 17 (current min is 9)

处理此类情况的正确方法是什么?谢谢!

1 个答案:

答案 0 :(得分:1)

检查用户的版本

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

}else{

}

然后只是抑制lint错误