android應用實現重啓系統+簽名

 


目錄[-]java

1.在AndroidManifest.xml文件的manifest標籤中加入一條android:sharedUserId="android.uid.system"android

01 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
02     package="com.ipanel.update"
03     android:versionCode="1"
04     android:versionName="1.0"
05     android:sharedUserId="android.uid.system" >
06
07     <uses-sdk
08         android:minSdkVersion="9"
09         android:targetSdkVersion="15" />  
10     <uses-permission android:name="android.permission.INTERNET"/>
11     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
12     <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
13
14     <application
15         android:icon="@drawable/ic_launcher"
16         android:label="@string/app_name"
17         android:theme="@style/AppTheme" >
18         <activity
19             android:name=".MainActivity"
20             android:label="@string/title_activity_main" >
21             <intent-filter>
22                 <action android:name="android.intent.action.MAIN" />
23
24                 <category android:name="android.intent.category.LAUNCHER" />
25             </intent-filter>
26         </activity>
27     </application>
28
29 </manifest>

2.在MainActivity中,有如下2種方式實現:web

1 /*Intent reboot = new Intent(Intent.ACTION_REBOOT); 
2     reboot.putExtra("nowait", 1); 
3     reboot.putExtra("interval", 1); 
4     reboot.putExtra("window", 0); 
5     sendBroadcast(reboot); */
6 PowerManager pManager=(PowerManager) getSystemService(Context.POWER_SERVICE);
7 pManager.reboot("");

整個代碼:app

01 package com.demo.reboot;
02
03 import java.io.File;
04 import java.io.IOException;
05 import java.io.InputStream;
06
07 import android.app.Activity;
08 import android.app.AlertDialog;
09 import android.content.Context;
10 import android.content.DialogInterface;
11 import android.content.Intent;
12 import android.os.Bundle;
13 import android.os.PowerManager;
14 import android.view.View;
15 import android.view.View.OnClickListener;
16 import android.widget.Button;
17
18 public class MainActivity extends Activity {
19
20     @Override
21     public void onCreate(Bundle savedInstanceState) {
22         super.onCreate(savedInstanceState);
23         setContentView(R.layout.activity_main);
24
25         Button rebootBtn = (Button) findViewById(R.id.button2);
26         rebootBtn.setOnClickListener(new OnClickListener() {
27             @Override
28             public void onClick(View v) {
29                 new AlertDialog.Builder(MainActivity.this)
30                 .setTitle("提示")
31                 .setMessage("確認重啓麼?")
32                 .setPositiveButton("重啓", new DialogInterface.OnClickListener() {
33                     @Override
34                     public void onClick(DialogInterface dialog, int which) {
35                         // 重啓
36                         /*String str = "重啓";
37                         try {
38                             str = runCmd("reboot", "/system/bin");
39                         } catch (IOException e) {
40                             e.printStackTrace();
41                         }*/
42                         /*Intent reboot = new Intent(Intent.ACTION_REBOOT); 
43                         reboot.putExtra("nowait", 1); 
44                         reboot.putExtra("interval", 1); 
45                         reboot.putExtra("window", 0); 
46                         sendBroadcast(reboot); */
47                         PowerManager pManager=(PowerManager) getSystemService(Context.POWER_SERVICE);
48                         pManager.reboot("重啓");
49                         System.out.println("execute cmd--> reboot\n" + "重啓");
50                     }
51                 })
52                 .setNegativeButton("取消", new DialogInterface.OnClickListener() {
53                     @Override
54                     public void onClick(DialogInterface dialog, int which) {
55                         // 取消當前對話框
56                         dialog.cancel();
57                     }
58                 }).show();
59             }
60
61         });
62     }
63
64 }

3.給apk簽名

簽名方法:ide

loop  android簽名機制(2)——如何簽名工具

1>添加權限oop

    在AndroidManifest.xml文件下添加android:sharedUserId="android.uid.system" 。ui

2>在Eclipse中導出無簽名的應用文件this

   在工程中:右鍵->Android Tools -> Export Unsigned Application Package導出應用

3>找出系統簽名密鑰

   系統密鑰爲: platform.pk8和platform.x509.pem

   路徑: build\target\product\security 

4>找出系統簽名工具  

   工具爲:signApk.jar 

   路徑:/out/host/linux-x86/framework/ signApk.jar 

 

5>開始簽名

  將第二、三、4步找到的無簽名應用、platform.pk八、platform.x509.pem和signApk.jar放到同一文件夾下如F:\sign。

  打開 dos 操做界面,定們到F:\sign,輸入命令:

  java -jar  signapk.jar  platform.x509.pem  platform.pk8 **.apk   ***.apk 

(**.apk 爲未簽名應用  ***.apk 爲簽名以後應用)

 注:以前在評論裏有錯誤的說過這個簽名工具是通用的,這裏糾正下。編譯導出的apk,要安裝到那個版本的系統,就去那源碼裏找對應的簽名工具,並非各個版本通用

相關文章
相關標籤/搜索