Installing an APK using pm command(使用 pm 命令安装 APK)
问题描述
我尝试使用此代码更新 APK:
I tried updating an APK using this code:
Process process;
process = Runtime.getRuntime().exec(new String[] {"su", "-c", "pm install -r -d"+MyApk.apk});
但它不起作用.
当我将它与 adb 一起使用时效果很好:
This works well when I use it with adb like:
adb shell su -c pm install -r -d /system/app/Community-debug.apk
如果它必须请求用户许可才能像使用意图方法一样安装,它也可以正常工作.
It also works fine if it has to ask for user permission in order to install like using the intent method.
推荐答案
您的应用程序需要以系统用户身份运行才能访问此级别的命令.如果您的应用程序使用标准渠道分发,则无法以任何方式完成,例如Google Play、从 SD 卡安装或通过 ADB 安装.这些都不会让您的应用破坏安全性.
Your application would need to run as System user to access this level of commands. It cannot be done in any way if your app is distributed using standard channels, e.g. Google Play, installing from SD card, or installing by ADB. None of these would let your app breach the security.
话虽如此,有一种让它工作的方法,但这种方法只适用于特权分发.您的应用必须:
Having said that, there is a way to get it working, but that way is for privileged distribution only. Your app must:
- 在 AndroidManifest 中包含
android:sharedUserId="android.uid.system" - 使用用于对系统其余部分进行签名的证书进行签名
- 预安装在以下特权位置之一:
/system/app、/system/priv-app
一旦您的应用满足这些要求,它就可以执行诸如 pm install 之类的命令,即使没有 su
Once your app satisfies these requirements, it can execute commands like pm install, even without the su
不用说,此类选项仅适用于销售自有品牌设备的电信提供商等大型机构.
Needless to say that such options are only available to large bodies like telecom providers who sell their own-branded devices.
这篇关于使用 pm 命令安装 APK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 pm 命令安装 APK
基础教程推荐
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
