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();
        }
    }

この 2 番目のバージョン (機内モード) は機能しません:

    @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

現在、保護された放送としてGoogleが制限しているため、ジェリービーンよりも高い機内モードを回転させることはできません

于 2014-09-09T11:16:49.847 に答える