apk,静默安装,linux命令
来源:互联网 发布:移动软件开发定义 编辑:程序博客网 时间:2024/06/14 17:54
import android.content.Context;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;public class LinuxCmdUtil {private static final String closeEth0="busybox ifconfig eth0 down";private static final String openEth0="busybox ifconfig eth0 up";//String val = execRootCmd("cat /sys/class/amhdmitx/amhdmitx0/cec_active");public static void CloseEth0(){String val = execRootCmd(closeEth0);}public static void openEth0(){String val = execRootCmd(openEth0);}public static void startApp(){String startAppString="pm start -n [package+MainActivity]";String val = execRootCmd(startAppString);} private static final String getCateWayIp=" cat /proc/net/arp";//获得网关Ip的Linux指令 public static String getCateWayIp(){String val = LinuxCmdUtil.execRootCmd(getCateWayIp);return val; }/** *重启 */public static void restart(){LinuxCmdUtil.execRootCmd("reboot");}public static void installApK(String installPath,Context mContext){ // 核心是下面几句代码 // Intent intent = new Intent(Intent.ACTION_VIEW); // intent.setDataAndType(Uri.fromFile(new File(installPath)), // "application/vnd.android.package-archive"); // mainActivity.startActivity(intent);StringBuilder installCmdBuilder=new StringBuilder("pm install -r ");installCmdBuilder.append(installPath);String val = execRootCmd(installCmdBuilder.toString());}public static String execRootCmd(String cmd) {String result = "";DataOutputStream dos = null;DataInputStream dis = null;try {Process p = Runtime.getRuntime().exec("su");dos = new DataOutputStream(p.getOutputStream());dis = new DataInputStream(p.getInputStream());dos.writeBytes(cmd + "\n");dos.flush();dos.writeBytes("exit\n");dos.flush();String line = null;while ((line = dis.readLine()) != null) {result += line;}p.waitFor();} catch (Exception e) {e.printStackTrace();} finally {if (dos != null) {try {dos.close();} catch (IOException e) {e.printStackTrace();}}if (dis != null) {try {dis.close();} catch (IOException e) {e.printStackTrace();}}}return result;}}
linux命令执行可参考:http://www.jianshu.com/p/603f29a6a513
0 0
- apk,静默安装,linux命令
- Android采用pm命令静默安装apk
- 静默安装apk,静默卸载apk
- 静默安装APK
- android 静默安装apk
- android 静默安装Apk
- Android静默安装apk
- android静默安装apk
- android apk静默安装
- Android静默安装apk
- 静默安装apk
- android APK静默安装
- apk 静默安装
- 关于静默安装apk
- 静默安装apk
- Android 静默安装apk
- android静默安装、静默卸载apk方法
- 关于apk的 静默安装
- 循环链表
- JAVA 代码优化常用方法
- lingo学习
- C++ 友元
- 常用的电平转换方法
- apk,静默安装,linux命令
- 2017TP-LINK软件实习生笔试面试回顾
- JS限制文本框输入金额并保留两位小数
- Python学习笔记(一)——Anaconda入门
- 条形码扫描技术
- [leetCode刷题笔记]284. Peeking Iterator
- 字和字节和位的关系
- Web前端复习——Javascript(字符串)
- phpmyadmin导入数据库提示:超出 PHP 限制