安卓飞行模式连续切换



我已经编写了某些代码,以便我的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) {
        }
    }
        }   
    }
 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);

检查一下这个,我认为这会帮助你..

最新更新