praba230890
praba230890

Reputation: 2320

Is it possible to turn on and off airplane mode in android wear programmatically

Upto API level 16, it is possible to turn on/off airplane mode in Android devices. From API level of 17, it seems like the Settings.Global, which is read only has replaced the Settings.System.

I want to know that, is it possible to turn on/off the airplane mode programmatically in android wear (Moto 360) which isn't rooted.

enter image description here enter image description here

Upvotes: 1

Views: 1136

Answers (1)

krishnan muthiah pillai
krishnan muthiah pillai

Reputation: 2741

This code works properly on Rooted Device.

To Turn ON:

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

To Turn Off:

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

Upvotes: 1

Related Questions