国产探花免费观看_亚洲丰满少妇自慰呻吟_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);

    }

}

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 左权县| 谢通门县| 宿迁市| 甘孜| 平湖市| SHOW| 昭平县| 迭部县| 金塔县| 日照市| 泰兴市| 洞口县| 扶沟县| 东兰县| 莱阳市| 海宁市| 乌鲁木齐县| 泽普县| 盐亭县| 城固县| 济宁市| 昌都县| 奉化市| 镇康县| 锡林郭勒盟| 荣成市| 铜鼓县| 琼中| 邢台县| 额济纳旗| 商河县| 文登市| 朝阳区| 嘉荫县| 当雄县| 东丰县| 随州市| 荔波县| 吉木乃县| 兰溪市| 海门市|