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,要安装到那个版本的系统,就去那源码里找对应的签名工具,并非各个版本通用

相关文章
相关标签/搜索