0

I had written certain code such that my android app should go to airplane mode and come back to connected mode with the network for around some time until i close the application forcibly. Its working with the code I had written but the problem is that the screen or display is not showing the flight symbol. When I go to settings, I can see that the code is enabling and disabling the air plane mode properly.

Can any one please give me a solution for this.

My code is as follows

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) {

        }
    }
        }   
    }
Bharath Gupta
  • 324
  • 3
  • 7
  • 20
  • is it affecting what you want to achieve ? other than the symbol on top.This happens sometimes with wifi also but it does not affect my output in any way – Sunny Kumar Aditya Apr 06 '12 at 07:46
  • yes. While running the app and if had gone to the settings and see I could clearly see that the check box for air plane mode is getting enabled and disabled.., but the i con in the notification bar is not showing that the phone is in airplane mode. – Bharath Gupta Apr 06 '12 at 08:29

1 Answers1

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

Check with this one., I think this will help you ..

Satheeshkumar
  • 437
  • 4
  • 13
  • I dont think this meets my requirement... Check my requirement again post your view dude, as yours just make my app to set to airplane mode.But i wanna get back the connected mode and again to airplane mode(flight mode) continuously. – Bharath Gupta Apr 06 '12 at 11:18