2

I am trying to disallow the user to use the long key press of the power button for security application and I have tried the on long key press method but the dialog still appears is there any way to disable the dialog from appearing?

dythe
  • 840
  • 5
  • 21
  • 45

4 Answers4

1

Just try this

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

            Log.d("Focus debug", "Focus changed !");

        if(!hasFocus) {
            Log.d("Focus debug", "Lost focus !");

            Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            sendBroadcast(closeDialog);
        }
    }
wawan
  • 11
  • 1
0

It is not possible from the Android API, as mentioned here:

How to disable power button?

Community
  • 1
  • 1
Adam Monos
  • 4,287
  • 1
  • 23
  • 25
-1

I believe this is not possible. But even if you could do it, isnt it possible to remove battery which would defeat the whole point.

nandeesh
  • 24,740
  • 6
  • 69
  • 79
  • Is it possible to over wrote this behavior by trying to use the power button asba camera shutter? Saw this suggestion in another question – dythe Jul 30 '12 at 10:44
  • i think only Custom ROM can do this. Since power button is handled in frameworks, the power button event will not reach the app. – nandeesh Jul 30 '12 at 10:48
-4

Just use the disable() method.

$Button1->Shutdown.disable();

MySQL
  • 181
  • 2
  • 2
  • 11