国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android實現系統重新啟動的功能

2020-04-11 12:00:15
字體:
來源:轉載
供稿:網友

首先定義布局文件:

復制代碼 代碼如下:

<?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",這是為了讓應用分享一個系統級別的UID,否則會出現權限拒絕的錯誤。
類文件:

復制代碼 代碼如下:

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

    }

}

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泗阳县| 曲靖市| 麻栗坡县| 包头市| 巴中市| 临潭县| 裕民县| 西峡县| 通河县| 伊宁市| 宁晋县| 五峰| 扎赉特旗| 龙井市| 万年县| 广饶县| 滦南县| 盐津县| 昌邑市| 腾冲县| 平度市| 天水市| 莱阳市| 和平县| 嘉禾县| 类乌齐县| 会宁县| 温泉县| 咸阳市| 宁乡县| 绥宁县| 扎囊县| 凤山县| 莱西市| 辛集市| 萨嘎县| 玉门市| 安宁市| 绥阳县| 孟村| 阿拉善盟|