2

我需要一些帮助,并希望通过问你,聪明的人找到一个建议。我想在 Android JellyBean/Kitkat(API 17+)上切换到飞行模式......我搜索了几个小时,但没有得到工作结果/信息。目前我只能关闭 WLAN 和移动数据 - 但只有在切换到飞行模式后才会禁用手机连接,对吧?

这有效:

 public void manual_switch_off()
    {
        WifiManager wifiManager;
        wifiManager = (WifiManager) this.getSystemService(this.WIFI_SERVICE);
        wifiManager.setWifiEnabled(false);
        ConnectivityManager dataManager;
        dataManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        Method dataMtd = null;
        try
        {
            dataMtd = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", boolean.class);
        } catch (NoSuchMethodException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        dataMtd.setAccessible(true);
        try
        {
            dataMtd.invoke(dataManager, false);
        } catch (IllegalArgumentException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

第二个版本(飞行模式)不起作用:

    @SuppressWarnings("deprecation")
public void airPlanemodeON()
{
    boolean isEnabled = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;
    if (isEnabled == false)
    {
        modifyAirplanemode(true);
        Toast.makeText(getApplicationContext(), "Airplane Mode ON", Toast.LENGTH_LONG).show();
    }
}

@SuppressWarnings("deprecation")
public void airPlanemodeOFF()
{
    boolean isEnabled = Settings.System.getInt(this.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1;
    if (isEnabled == true)// means this is the request to turn ON AIRPLANE mode
    {
        modifyAirplanemode(false);
        Toast.makeText(getApplicationContext(), "Airplane Mode OFF", Toast.LENGTH_LONG).show();
    }
}

@SuppressWarnings("deprecation")
public void modifyAirplanemode(boolean mode)
{
    Settings.System.putInt(getContentResolver(), Settings.System.AIRPLANE_MODE_ON, mode ? 1 : 0);// Turning ON/OFF Airplane mode.

    Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);// creating intent and Specifying action for AIRPLANE mode.
    intent.putExtra("state", !mode);// indicate the "state" of airplane mode is changed to ON/OFF
    sendBroadcast(intent);// Broadcasting and Intent

}

我将权限设置为清单。有人说我可以使用 Titanium Backup 将这个应用程序切换到系统应用程序,这真的有用吗?- 我希望能够将我的应用程序加载到 Play 商店 - 我可以想象,在将我的应用程序设为系统应用程序之后,它将不再可能,这是正确的吗?

非常感谢!

4

1 回答 1

2

目前你无法实现高于果冻豆的飞行模式,因为谷歌限制它作为受保护的广播

于 2014-09-09T11:16:49.847 回答