欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android實現(xiàn)系統(tǒng)重新啟動的功能

 更新時間:2013年11月19日 10:28:20   作者:  
有些Android版本沒有系統(tǒng)重啟的功能,非常不方便。需要我們自己開發(fā)一個能夠重新啟動的應用

首先定義布局文件:

復制代碼 代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.hzhi.restart"
    android:versionCode="1"
    android:versionName="1.0"
    android:installLocation="preferExternal"
    android:sharedUserId="android.uid.system">

    <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="com.hzhi.restart.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

布局文件其實很簡單,就是一個按鈕。注意android:sharedUserId="android.uid.system",這是為了讓應用分享一個系統(tǒng)級別的UID,否則會出現(xiàn)權(quán)限拒絕的錯誤。
類文件:

復制代碼 代碼如下:

package com.hzhi.restart;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

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

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

    public void click(View view){

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

    }

}

運行后會出錯,這是因為程序運行時,使用的是系統(tǒng)默認的簽名,而不是系統(tǒng)級別的簽名。解決方法是將默認的簽名刪除,替換成系統(tǒng)級別的簽名。

相關(guān)文章

最新評論