android应用实现重启系统
来源:互联网 发布:linux svn 分支 编辑:程序博客网 时间:2024/06/01 07:15
.在AndroidManifest.xml文件的manifest标签中加入一条android:sharedUserId="android.uid.system"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ipanel.update"
android:versionCode="1"
android:versionName="1.0"
android:sharedUserId="android.uid.system" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
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 a.apk b.apk
(a.apk 为未签名应用 b.apk 为签名之后应用)
- android应用实现重启系统
- android应用实现重启系统
- android应用实现重启系统+签名
- android应用实现重启系统
- android应用实现重启系统
- android应用实现重启系统
- Android 应用实现系统重启reboot
- Android 应用实现系统重启reboot
- android应用实现重启
- android 应用重启实现
- 如何实现Android重启应用程序代码 ?
- cocos2dx android 实现应用重启
- android APK实现系统重启
- Android系统重启的实现方式
- 代码实现Android系统重启
- Android实现系统关机和重启
- android 应用重启系统 需要系统签名
- android 2种切换语言方式:应用内切换和随系统而切换 代码实现重启应用
- Coder-Strike 2014 - Qualification Round B. Multi-core Processor
- 滑动换屏——fragment
- struts2中文乱码问题
- 在c++,c中宏的使用和全局静态变量的使用
- SSH2免密码登录OpenSSH
- android应用实现重启系统
- 做题过程中的总结
- 数据结构学习笔记(11.递归的应用之常用递归算法)
- 重温Java(一)
- VS2010 中如何使用ankhsvn 插件(远程服务器)
- ACM Numerical Summation of a Series (ZOJ-1007) 的N阶求解算法
- linux系统常见命令(转载,忘记出处)
- Codeforces Round #241 (Div. 2) A题
- 两个SSH2间免密码登录