Aerrow
Aerrow

Reputation: 12134

Reboot code is not work for me

I used below sample code to restart my mobile by programattically but it won't work for me. Kindly suggest here what's the wrong i did?

Reboot.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();
        // }
    }

}

Manifest.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>

Upvotes: 0

Views: 351

Answers (1)

jtt
jtt

Reputation: 13541

You cannot call su on a production device if the device is not rooted. Rooted means that you have more access/permissions on the device (it can be a security risk). If you did not setup the device for root, then it is NOT rooted, therefore you cannot su.

Upvotes: 1

Related Questions