Handle alert when shut down device android in rooted app

528 views Asked by At

I want change this message "Your phone is shut down" that appear when shut down the device.enter image description here

Do you have any ideas?

My app download videos in the background, I must warn you not to switch off the device if the download is not yet finished, such as happens when you shut down Windows and is downloading updates.

2

There are 2 answers

0
Ortensia C. On BEST ANSWER

In AndroidManifest.xml:

<uses-permission android:name="android.permission.PREVENT_POWER_KEY" />
<uses-permission android:name="android.permission.DEVICE_POWER"
    tools:ignore="ProtectedPermissions" />

MainActivity.java I intercept the power off button and force close system dialog and create a View custom above it

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_POWER) {
        // Do something here...
        event.startTracking(); // Needed to track long presses

        Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
        sendBroadcast(closeDialog);
        mViewCustom.setVisibility(View.VISIBLE);

        return true;
    }
    return super.onKeyDown(keyCode, event);
}

@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_POWER) {

        return true;
    }
    return super.onKeyLongPress(keyCode, event);
}
0
betorcs On

Adriana take a look at Intent.ACTION_SHUTDOWN, i am not sure if you can handle like you want.

Additionally this post is related to this.