今天來記錄一下Shutdown和Reboot分別如何使用app Java code實現
首先定義以下這兩個method
    private void doShutdown() {
        Intent intent = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");
        intent.putExtra("android.intent.extra.KEY_CONFIRM", false);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
    private void doReboot() {
        Intent intent = new Intent(Intent.ACTION_REBOOT);
        intent.putExtra("nowait", 1);
        intent.putExtra("interval", 1);
        intent.putExtra("window", 0);
        try {
            startActivity(intent);
        } catch (Exception e) {
            Log.d(TAG, e.getMessage());
        }
    }
之後還需要在AndroidManifest.xml增加
<manifest 
...
android:sharedUserId="android.uid.system" >
<uses-permission android:name="android.permission.SHUTDOWN" />
在Android.mk增加
LOCAL_CERTIFICATE := platform
放進系統的codebase 一起build出apk之後再安裝才行!
簡單的說就是一般app是無法有權限做這兩件事情的![]()