高达API等级16,可以在Android设备中打开/关闭飞行模式。从API级别17开始,SparseArray<Fragment>
似乎只读取了Settings.System
。
我想知道,是否有可能以android编程(Moto 360)编程方式打开/关闭飞机模式。
答案 0 :(得分:1)
此代码在Rooted Device上正常运行。
开启:
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Process process;
process = Runtime.getRuntime().exec("su -c settings put global airplane_mode_on 1;am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
关闭:
b2=(Button)findViewById(R.id.button1);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
try {
Process process;
process = Runtime.getRuntime().exec("su -c settings put global airplane_mode_on 0;am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});