Back to project page android-power-button-fix.
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.
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(); } }