2012-04-06 35 views
0

我已经写了某些代码,以便我的android应用程序应该转到飞行模式并在网络上回到连接模式一段时间,直到我强行关闭应用程序为止。 它与我写的代码一起工作,但问题是屏幕或显示屏没有显示飞行符号。 当我进入设置时,我可以看到代码正在启用​​和禁用飞机模式。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) { 

     } 
    } 
     } 
    } 
+0

被它影响了你想要达到什么样的?除了顶部的符号。有时也会发生这种情况,无线也可以,但它不会以任何方式影响我的输出 – 2012-04-06 07:46:53

+0

是的。当运行应用程序,如果已经去了设置,并看到我可以清楚地看到,飞机模式的复选框正在启用和禁用..,但通知栏中的我没有显示手机在飞机上模式。 – 2012-04-06 08:29:27

回答

0
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); 

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

+0

我不认为这符合我的要求...检查我的要求再发布您的看法哥们,因为你只是让我的应用程序设置为飞行模式。但我想回到连接模式,并再次飞行模式(飞行模式)连续。 – 2012-04-06 11:18:15

相关问题