我需要一些帮助,希望通过问你聪明的人来寻求建议。我想在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将这个应用程序切换到系统应用程序,这真的有用吗? - 我希望能够将我的应用程序加载到游戏商店 - 我可以想象,在将我的应用程序作为系统应用程序之后,它将不再可能,这是正确的吗?
非常感谢!
答案 0 :(得分:2)
目前你无法实现高于软糖的飞行模式,因为谷歌将其限制为受保护的广播