thorgil
thorgil

Reputation: 59

App to turn off airplane mode on android

First little background why i need to write this app. My phone got wet and unfortunately screen doesn't work now (I can't see anything and I can't press anything). Phone has airplane mode turn on so my photos cannot synchronize. I cannot connect with USB cable because it is in "Only recharge state". USB debugging is turn off so I cannot connect with adb to turn off airplane mode. But there is a little light in a tunnel. There is WIFI working. I hear a sound when it connects to my network so I know it's working. My idea is to write a simple app that will turn off airplane mode. I'll install it from PC using Play Store but I need a way to turn it on. I think it can be done by registering this app as a listener to some system call. Can Play Store register app as a listener without a need to run this app?

Do you think that's all possible? Maybe someone has other idea?

Thanks!

Upvotes: 1

Views: 6908

Answers (2)

Anthony
Anthony

Reputation: 3074

From android 4.2: This is no longer possible, except by apps that are signed by the firmware signing key or are installed on the system partition (typically by a rooted device user). (Copied from here)

Android 4.1 and below:

// read the airplane mode setting
boolean isEnabled = Settings.System.getInt(
      getContentResolver(), 
      Settings.System.AIRPLANE_MODE_ON, 0) == 1;

// toggle airplane mode
Settings.System.putInt(
      getContentResolver(),
      Settings.System.AIRPLANE_MODE_ON, isEnabled ? 0 : 1);

// Post an intent to reload
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", !isEnabled);
sendBroadcast(intent);

Also add the WRITE_SETTINGS permission to your android manifest

Copied from here

You may be able to open the settings with this code and tell the user to disable airplane mode:

if (android.os.Build.VERSION.SDK_INT < 17){
    try{
        Intent intentAirplaneMode = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
        intentAirplaneMode.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intentAirplaneMode);
    }
    catch (ActivityNotFoundException e){
        Log.e("exception", e + "");
    }
}
else{
    Intent intent1 = new Intent("android.settings.WIRELESS_SETTINGS");
    intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent1);
}

Coped from here

Upvotes: 1

Saumik Bhattacharya
Saumik Bhattacharya

Reputation: 951

Currently I am not aware how to programmatically build an app to turn on/off system settings, but what I can tell you is, there is an app already available in Play Store which I feel does the same thing.

You can have a look at this app, called Trigger.

https://play.google.com/store/apps/details?id=com.jwsoft.nfcactionlauncher&hl=en

All you have to do is to create a task to turn the Airplane mode Off and that task can be triggered through Wi-Fi.

Hope it helps.

Upvotes: 0

Related Questions