命令从手机安装应用程序?


Answers:


12

在adb shell或终端仿真器中(很可能是通过SSH),您可以使用该pm实用程序来安装应用程序。该命令是:

pm install /sdcard/app1.apk

以下是开关pm

usage: pm [list|path|install|uninstall]
       pm list packages [-f] [-d] [-e] [-u] [FILTER]
       pm list permission-groups
       pm list permissions [-g] [-f] [-d] [-u] [GROUP]
       pm list instrumentation [-f] [TARGET-PACKAGE]
       pm list features
       pm list libraries
       pm path PACKAGE
       pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
       pm uninstall [-k] PACKAGE
       pm clear PACKAGE
       pm enable PACKAGE_OR_COMPONENT
       pm disable PACKAGE_OR_COMPONENT
       pm setInstallLocation [0/auto] [1/internal] [2/external]

The list packages command prints all packages, optionally only
those whose package name contains the text in FILTER.  Options:
  -f: see their associated file.
  -d: filter to include disbled packages.
  -e: filter to include enabled packages.
  -u: also include uninstalled packages.

The list permission-groups command prints all known
permission groups.

The list permissions command prints all known
permissions, optionally only those in GROUP.  Options:
  -g: organize by group.
  -f: print all information.
  -s: short summary.
  -d: only list dangerous permissions.
  -u: list only the permissions users will see.

The list instrumentation command prints all instrumentations,
or only those that target a specified package.  Options:
  -f: see their associated file.

The list features command prints all features of the system.

The path command prints the path to the .apk of a package.

The install command installs a package to the system.  Options:
  -l: install the package with FORWARD_LOCK.
  -r: reinstall an exisiting app, keeping its data.
  -t: allow test .apks to be installed.
  -i: specify the installer package name.
  -s: install package on sdcard.
  -f: install package on internal flash.

The uninstall command removes a package from the system. Options:
  -k: keep the data and cache directories around.
after the package removal.

The clear command deletes all data associated with a package.

The enable and disable commands change the enabled state of
a given package or component (written as "package/class").

The getInstallLocation command gets the current install location
  0 [auto]: Let system decide the best location
  1 [internal]: Install on internal device storage
  2 [external]: Install on external media

The setInstallLocation command changes the default install location
  0 [auto]: Let system decide the best location
  1 [internal]: Install on internal device storage
  2 [external]: Install on external media

例如,您可以强制应用直接安装到外部存储(Froyo / Gingerbread风格)。

PS该wget实用程序应可通过CM7上的BusyBox使用。如果没有,您可以随时通过Android Market进行安装。


这正是我在寻找的东西。pm确实存在于/system/bin/pm,但不幸的是通过SSH(即使是root用户)它也无能为力。运行任何pm命令都不会产生任何输出。我做错什么了吗?它确实可以在终端仿真器中工作,但由于某些原因不能通过SSH :(
Naftuli Kay 2011年

我已经从CM6的adb中以root用户身份进行过PM工作;除此之外,我不确定。
Broam 2011年

1
请问为什么您更喜欢SSH而不是ADB Shell?
Chahk 2011年

1
@Chahk:adb只能通过USB电缆工作,不是吗?SSH可以通过无线网络进行。另外,ssh到处都有,但adb必须安装。
imz-伊万·扎哈拉里谢夫(Ivan Zakharyaschev)2012年

错误:java.lang.SecurityException:权限拒绝:pm命令的runInstallCreate要求以用户-1的身份运行,但正在从用户11调用;这需要android.permission.INTERACT_ACROSS_USERS_FULL

6

我建议您将手机插入安装了sdk(或至少adb)并处于调试模式的PC。之后,编写一个脚本,遍历您的应用程序并通过adb安装它们,例如adb install x:\path\to\app1.apk


电话上没有本机实用程序可以执行此操作吗?
Naftuli Kay 2011年

1
不可以,因为大多数应用程序只是将其.apk文件复制到/ data / app。您可以尝试将所有的APK复制到那里,然后重新启动(请注意,这需要root用户,但是我假设您从cyanogenmod标记中获取了根)。
onik 2011年

现在就是我可以通过SSH进行的操作cp * /data/app && reboot
Naftuli Kay 2011年

1
请注意,cp命令在现货的Android(即非定制ROM)中不可用,因此,如果您不使用Cyanogen,则可能需要(ab)使用该cat命令。
Lie Ryan

2
实际上,在电话上有这样的命令。 pm install /sdcard/app1.apkadb install执行与adb shell,终端仿真器相同的操作,并且可以在SSH中执行。查看pm更多选项的输出。甚至有一个开关可以强制应用程序直接安装到外部存储(姜饼风格)。
Chahk 2011年

2

我正在使用相同的方法,是的,SSH非常棒!但是似乎当您将SSH连接到Android时,它会获得与sh不同的shell,因此,如果将sh放在命令前面,它应该可以工作。

这是一个例子: sh /system/bin/pm install app1.apk

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.