SoFunction
Updated on 2025-04-12

Android implements system restart function

First define the layout file:

Copy the codeThe code is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:andro
    package=""
    android:versionCode="1"
    android:versionName="1.0"
    android:installLocation="preferExternal"
    android:sharedUserId="">

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=""
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="" />

                <category android:name="" />
            </intent-filter>
        </activity>
    </application>

</manifest>

The layout file is actually very simple, just a button. Note android:sharedUserId="", which is to let the application share a system-level UID, otherwise there will be a permission denied error.
Class files:

Copy the codeThe code is as follows:

package ;

import ;
import ;
import ;
import ;
import ;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;
    }

    public void click(View view){

        Intent intent = new Intent();
        (Intent.ACTION_REBOOT);
        ("nowait", 1);
        ("interval", 1);
        ("startTime", 1);
        ("window", 0);
        sendBroadcast(intent);

    }

}

An error occurs after running, because the program is running, using the system default signature, not the system-level signature. The solution is to delete the default signature and replace it with a system-level signature.