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