How to enable / disable airplane mode in android?

I am writing an Android application that should turn off the cell phone signals for a certain period of time and I need to turn the signal back on. Can someone help me with this?

Thanks in advance.


Hi, Thanks for the answers below, this works on a virtual device. But this does not work for a real device (Samsung Galaxy y) :(, pls, someone can tell why this is?

+4
source share
2 answers

try the following:

public void onClick(View v){ context = getApplicationContext(); if (((ToggleButton)v).isChecked()){ boolean isEnabled = Settings.System.getInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, 0) == 1; if(isEnabled == false) { Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,1); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", 1); context.sendBroadcast(intent); } }else { Settings.System.putInt(context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON,0); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", 0); context.sendBroadcast(intent); } }; }); 

In another part of the code, change number one to number 0.

+1
source

Look at this page here.

http://dustinbreese.blogspot.com/2009/04/andoid-controlling-airplane-mode.html

// Switch airplane mode.

  Settings.System.putInt( context.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1); 

// Put the intention to reload.

 Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.putExtra("state", !isEnabled); sendBroadcast(intent); where isEnabled is whether airplane mode is enabled or not. 
0
source

Source: https://habr.com/ru/post/1400039/


All Articles