Android的关闭飞行模式,在版本> = 4.1 [英] Android Disable airplane mode at version >=4.1

查看:467
本文介绍了Android的关闭飞行模式,在版本> = 4.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在我的信息亭应用关闭飞行模式,我想下面的代码片段覆盖设备设置

I need to disable airplane mode in my kiosk app, i tried snippet below to overwrite device settings

try {
    int airplane = Settings.System.getInt(getApplicationContext().getContentResolver(), "airplane_mode_on");
    if (airplane == 1) {
        getApplicationContext().sendBroadcast(new Intent("android.intent.action.AIRPLANE_MODE").putExtra("state", false));
    }
} catch (SettingNotFoundException e) {
    e.printStackTrace();
}

这code似乎工作起来到Android 4.0版本,而在4.1和它上面没有works.I希望让它生根设备访问系统设置工作。 其实我的任务是从关系,数位板状态栏关闭飞行模式功能。让我知道这些的任何建议实施。

This code seems to work up to android version 4.0, whereas in 4.1 and above it doesn't works.I hope to make it work by rooting the device to access the system settings. Actually my task to disable airplane mode feature from status bar in nexus tablet. Let me know any suggestions on these to implement.

推荐答案

有关Android的< = 4.1:

For Android <= 4.1:

static boolean getAirplaneMode(Context context)
{
   return Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) != 0;
}


static void setAirplaneMode(Context context, boolean mode)
{
   if (mode != getAirplaneMode(context))
   {
      Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, mode ? 1 : 0);
      Intent newIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
      newIntent.putExtra("state", mode);
       context.sendBroadcast(newIntent);
    }
}

有关Android的4.2看一看<一href="http://stackoverflow.com/questions/13422527/modify-airplane-mode-on-on-android-4-2-and-above/15448650#15448650">Modify AIRPLANE_MODE_ON在Android 4.2(及以上)

For Android 4.2 have a look at Modify AIRPLANE_MODE_ON on Android 4.2 (and above)

这篇关于Android的关闭飞行模式,在版本&GT; = 4.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆