0

From my activity A open a device setting page with firing the intent.can i listen back key press event on the device settings page.

e.gSettings.ACTION_APN_SETTINGS

bmargulies
  • 97,814
  • 39
  • 186
  • 310
User10001
  • 1,295
  • 2
  • 18
  • 30

1 Answers1

2

Assuming your settings page is an Activity, you can override the onBackPressed() method:

@Override
public void onBackPressed() {
    // Do stuff.
}

or

@Override
protected boolean onKeyDown(int keyCode, KeyEvent event) {
    // Do stuff if event == KeyEvent.KEYCODE_BACK.
}

Edit.

If you're thinking of listening (and processing) back presses in Activity A while your settings page is displayed, consider using a Fragment for your settings page, which you add and display in Activity A.

Edit 2 - answer to your comment:

As far as I know, there is no way to listen for e.g. wifi on/off clicks, but what you can do is the following:

startActivityForResult(new Intent(Settings.ACTION_WIFI_SETTINGS), 0xB00B);

then

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK && requestCode == 0xB00B) {
        // Check if WIFI is on/off. That way you know what the user pressed.
    }
}
Tadej
  • 2,901
  • 1
  • 17
  • 23
  • I am talking about device settings from where we on/off bluetooth,wifi etc.and i am opening this from my activity with below intent. startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)); – User10001 Mar 14 '14 at 10:29
  • For Some Settings page onActivityResult method return immediately even the setting page is open. – User10001 Mar 14 '14 at 11:31
  • 1
    According to [this thread](http://stackoverflow.com/q/3354955/905349), what you’re experiencing might be a bug. Could you get away with just checking if e.g. WiFi or bluetooth is on, then performing required actions? It seems like a feasible solution. – Tadej Mar 14 '14 at 12:57