0

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!

thorgil
  • 49
  • 1
  • 5
  • if it is connected to the wifi, how comes your photos are not synchronizing? – njzk2 Jan 20 '16 at 16:19
  • 1
    If WiFi works, why it is not syncing? And it's not possible. Any `BroadcastReceiver` only get activated after the user opens the app for the first time. – Budius Jan 20 '16 at 16:54

2 Answers2

1

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

Community
  • 1
  • 1
apmartin1991
  • 3,064
  • 1
  • 23
  • 44
  • I was afraid of that... Unfortunately my phone has 4.4 android and it's unrooted... :/ Thank you for help – thorgil Jan 20 '16 at 16:13
  • I had made an edit for you with how to open up the settings to get the user to change airplane mode. If it helped give it an up vote - if it answers your question (better than other answers) then please mark it as correct. – apmartin1991 Jan 20 '16 at 16:21
0

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.

Saumik Bhattacharya
  • 891
  • 1
  • 12
  • 28
  • Unfortunately screen doesn't work so I cannot see any thing, also I cannot tap the screen. Creating anything is not an option. But thank you for idea. – thorgil Jan 20 '16 at 16:11
  • Okay! You can check if there are any other possibilities with that app or not. Otherwise I will not be able to help you. All the best :) – Saumik Bhattacharya Jan 20 '16 at 16:22