我写了一些代码,这样我的android应用程序应该进入飞行模式,并在大约一段时间内返回到网络连接模式,直到我强行关闭应用程序。它与我写的代码一起工作,但问题是屏幕或显示器没有显示飞行符号。当我转到设置时,我可以看到代码正确地启用和禁用了飞机模式。
有没有人能给我一个解决方案。
我的代码如下
public class Airplane_ModeActivity extends Activity implements Runnable{
private static final int SLEEP_TIME_VALUE = 10000;
private static Context context;
private static ContentResolver contentResolver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
context = getApplicationContext();
contentResolver = context.getContentResolver();
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", false);
sendBroadcast(intent);
Runnable runnable = new Airplane_ModeActivity();
Thread thread = new Thread(runnable);
thread.start();
}
public void run(){
while(true) {
while(0==Settings.System.getInt(contentResolver, Settings.System.AIRPLANE_MODE_ON, 0) ) {
Settings.System.putInt(contentResolver, Settings.System.AIRPLANE_MODE_ON, 1);
try {
Thread.sleep(SLEEP_TIME_VALUE);
}
catch (InterruptedException ie) {
}
}
try {
Thread.sleep(SLEEP_TIME_VALUE);
}
catch (InterruptedException ie) {
}
while(1==Settings.System.getInt(contentResolver, Settings.System.AIRPLANE_MODE_ON, 1) ) {
Settings.System.putInt(contentResolver, Settings.System.AIRPLANE_MODE_ON, 0);
try {
Thread.sleep(SLEEP_TIME_VALUE);
}
catch (InterruptedException ie) {
}
}
try {
Thread.sleep(SLEEP_TIME_VALUE);
}
catch (InterruptedException ie) {
}
}
}
}发布于 2012-04-06 18:01:25
boolean isEnabled = Settings.System.getInt(thisActivity.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) == 1;
Settings.System.putInt(thisActivity.getContentResolver(),Settings.System.AIRPLANE_MODE_ON,isEnabled ? 0 : 1);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", !isEnabled);
sendBroadcast(intent);看看这个,我想这会对你有帮助的。
https://stackoverflow.com/questions/10039429
复制相似问题