android系统签名工具,android应用实现重启系统+签名

1.在AndroidManifest.xml文件的manifest标签中加入一条android:sharedUserId="android.uid.system"

package="com.ipanel.update"

android:versionCode="1"

android:versionName="1.0"

android:sharedUserId="android.uid.system" >

android:minSdkVersion="9"

android:targetSdkVersion="15" />

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

android:name=".MainActivity"

android:label="@string/title_activity_main" >

2.在MainActivity中,有以下2种方式实现:

/*Intent reboot = new Intent(Intent.ACTION_REBOOT);

reboot.putExtra("nowait", 1);

reboot.putExtra("interval", 1);

reboot.putExtra("window", 0);

sendBroadcast(reboot); */

PowerManager pManager=(PowerManager) getSystemService(Context.POWER_SERVICE);

pManager.reboot("");

整个代码:

package com.demo.reboot;

import java.io.File;

import java.io.IOException;

import java.io.InputStream;

import android.app.Activity;

import android.app.AlertDialog;

import android.content.Context;

import android.content.DialogInterface;

import android.content.Intent;

import android.os.Bundle;

import android.os.PowerManager;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

public class MainActivity extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

Button rebootBtn = (Button) findViewById(R.id.button2);

rebootBtn.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

new AlertDialog.Builder(MainActivity.this)

.setTitle("提示")

.setMessage("确认重启么?")

.setPositiveButton("重启", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// 重启

/*String str = "重启";

try {

str = runCmd("reboot", "/system/bin");

} catch (IOException e) {

e.printStackTrace();

}*/

/*Intent reboot = new Intent(Intent.ACTION_REBOOT);

reboot.putExtra("nowait", 1);

reboot.putExtra("interval", 1);

reboot.putExtra("window", 0);

sendBroadcast(reboot); */

PowerManager pManager=(PowerManager) getSystemService(Context.POWER_SERVICE);

pManager.reboot("重启");

System.out.println("execute cmd--> reboot\n" + "重启");

}

})

.setNegativeButton("取消", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// 取消当前对话框

dialog.cancel();

}

}).show();

}

});

}

}

3.给apk签名

签名方法:

1>添加权限

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

2>在Eclipse中导出无签名的应用文件

在工程中:右键->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>开始签名

将第2、3、4步找到的无签名应用、platform.pk8、platform.x509.pem和signApk.jar放到同一文件夹下如F:\sign。

打开 dos 操作界面,定们到F:\sign,输入命令:

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

(**.apk 为未签名应用  ***.apk 为签名之后应用)

注:之前在评论里有错误的说过这个签名工具是通用的,这里纠正下。编译导出的apk,要安装到那个版本的系统,就去那源码里找对应的签名工具,并不是各个版本通用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值