Android Open Source - android-power-button-fix do Power Off Receiver






From Project

Back to project page android-power-button-fix.

License

The source code is released under:

GNU General Public License

If you think the Android project android-power-button-fix listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package it.glisco.powerbuttonbroken;
/*from w  ww .j a  va 2 s.  c o m*/
import android.app.AlertDialog;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

public class doPowerOffReceiver extends BroadcastReceiver {
    public doPowerOffReceiver() {
    }

    @Override
    public void onReceive(Context context, Intent intent) {


        new AlertDialog.Builder(context)
                .setIcon(android.R.drawable.ic_dialog_alert)
                .setTitle(R.string.quit)
                .setMessage(R.string.really_quit)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        try {
                            Process proc = Runtime.getRuntime()
                                    .exec(new String[]{ "su", "-c", "reboot -p" });
                            proc.waitFor();
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }


                    }

                })
                .setNegativeButton(R.string.no, null)
                .show();
        
        

    }
}




Java Source Code List

it.glisco.powerbuttonbroken.ApplicationTest.java
it.glisco.powerbuttonbroken.BootCompletedReceiver.java
it.glisco.powerbuttonbroken.MyAdminReceiver.java
it.glisco.powerbuttonbroken.MyLockScreenActivity.java
it.glisco.powerbuttonbroken.SensorService.java
it.glisco.powerbuttonbroken.doLockReceiver.java
it.glisco.powerbuttonbroken.doPowerOffReceiver.java