最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2013年11月19日 10:28:20   作者:  
有些Android版本沒有系統(tǒng)重啟的功能,非常不方便。需要我們自己開發(fā)一個(gè)能夠重新啟動(dòng)的應(yī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>

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

復(fù)制代碼 代碼如下:

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);

    }

}

運(yùn)行后會(huì)出錯(cuò),這是因?yàn)槌绦蜻\(yùn)行時(shí),使用的是系統(tǒng)默認(rèn)的簽名,而不是系統(tǒng)級(jí)別的簽名。解決方法是將默認(rèn)的簽名刪除,替換成系統(tǒng)級(jí)別的簽名。

相關(guān)文章

最新評(píng)論

巴中市| 庄浪县| 皋兰县| 白玉县| 广水市| 海兴县| 荆门市| 甘泉县| 巢湖市| 陕西省| 大同市| 屏边| 信阳市| 棋牌| 中阳县| 二连浩特市| 双峰县| 沿河| 南皮县| 五家渠市| 金沙县| 大埔县| 商都县| 隆德县| 岚皋县| 五台县| 德格县| 恩平市| 平原县| 吴旗县| 腾冲县| 桐乡市| 聂拉木县| 平邑县| 广河县| 苍梧县| 阳曲县| 望都县| 子长县| 滁州市| 秭归县|