我使用此代码在 android 上打开飞行模式:
Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 1);
newIntent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
newIntent.putExtra("state", true);
context.sendBroadcast(newIntent);
它适用于 API 16,但在 API 23 上不起作用,应用程序终止。我该怎么办?
第二个问题是:如何在没有root的情况下打开和关闭android中的移动数据?
最佳答案
根据 docs Settings.System.AIRPLANE_MODE_ON 常量自 API 级别 17 及更高版本起已弃用,这就是您的应用程序崩溃的原因。 你应该使用 Settings.Global.AIRPLANE_MODE_ON反而。
关于java - 打开和关闭飞行模式以及如何在 android 中打开移动数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45976473/