【问题标题】:How can I detect if device is in Airplane mode? [duplicate]如何检测设备是否处于飞行模式? [复制]
【发布时间】:2017-02-01 14:46:56
【问题描述】:

我想检测我的设备是否处于飞行模式以取消活动的网络操作。我该怎么做?

【问题讨论】:

    标签: android android-networking


    【解决方案1】:

    你可以使用这个方法:

    @SuppressWarnings("deprecation")
    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    public static boolean isAirplaneModeOn(Context context) {        
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
            return Settings.System.getInt(context.getContentResolver(), 
                    Settings.System.AIRPLANE_MODE_ON, 0) != 0;          
        } else {
            return Settings.Global.getInt(context.getContentResolver(), 
                    Settings.Global.AIRPLANE_MODE_ON, 0) != 0;
        }       
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 2015-02-26
      相关资源
      最近更新 更多