0

我使用下面的示例代码以编程方式重新启动我的手机,但它对我不起作用。请在这里建议我做错了什么?

重启.java

public class Reboot extends Activity implements View.OnClickListener {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        ((ImageButton) findViewById(R.id.restartButton))
                .setOnClickListener(this);
    }

    public void onClick(View v) {
        try {
            Process proc = Runtime.getRuntime().exec(
                    new String[] { "su", "-c", "reboot" });
            proc.waitFor();
        } catch (Exception ex) {
            Log.i("Reboot Code", "Could not reboot", ex);
        }

        //This method also i did, kindy un comment this code and then check
        // try {
        // Runtime.getRuntime().exec(
        // new String[] { "/system/bin/su", "-c", "reboot now" });
        // } catch (IOException e) {
        // e.printStackTrace();
        // }
    }

}

清单.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bootup_sample_app"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="4"
        android:targetSdkVersion="15" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.REBOOT"/>

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

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

</application>

</manifest>
4

1 回答 1

1

如果设备未获得 root 权限,则无法调用su生产设备。植根意味着您在设备上拥有更多访问权限/权限(这可能是安全风险)。如果您没有为 root 设置设备,那么它没有 root,因此您不能su.

于 2012-12-07T18:05:45.013 回答