使用pm命令安装APK [英] Installing an APK using pm command

查看:266
本文介绍了使用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:


  • include android:sharedUserId = android.uid.system 在AndroidManifest中

  • 使用用于签署系统其余部分的证书进行签名

  • 预先安装在其中一个特权用户中位置: / system / app / system / priv-app

  • include android:sharedUserId="android.uid.system" in the AndroidManifest
  • be signed with the certificate which is used to sign the rest of the system
  • be pre-installed in one of the privileged locations: /system/app, /system/priv-app

一旦您的应用满足了这些要求,即使没有 su,它也可以执行 pm install 之类的命令。

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆