安装APK流程

1. 打包APK并进行系统签名

系统签名是为了获得系统权限,比如实现关机指令。
用到系统权限的apk,起签名必须使用系统签名,否则安装不上,会报错误。
详情可以参考这篇文章。
Android studio打包APK流程及给APK系统签名步骤

2. APK安装

2.1 图形界面安装

图形界面安装较为简单:

  1. 在文件管理中找到 apk 文件进行安装
  2. 允许各权限后,即可安装成功

2.2 指令安装

有两种方式可以在android模拟器或真机上使用命令行安装apk

一种是使用adb install命令,网上通常是这种方式

另一种是通过android提供的命令,pm install。

需要先进入android命令行:adb shell

然后执行对应pm命令。

我使用的为Android下的pm命令,以后有机会再写一篇另一种方式

2.2.1 Usage

usage: pm [list|path|install|uninstall]
       pm list packages [-f]
       pm list permission-groups
       pm list permissions [-g] [-f] [-d] [-u] [GROUP]
       pm list instrumentation [-f] [TARGET-PACKAGE]
       pm list features
       pm path PACKAGE
       pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
       pm uninstall [-k] 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.  Options:
  -f: see their associated file.

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 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

2.2.2 具体使用方法

  1. 察看已安装的包:
    pm list package
    此时则显示所有已经安装的包名。

    pm list package -f
    也显示associated文件所在目录(即保存的APK文件)

  2. 察看已知的权限组:
    pm list permission-groups

  3. 察看所有已知的权限:
    pm list permissions

  4. 列出所有硬件相关信息:
    pm list features

  5. 列出指定包名的 associated 文件 (APK存档文件) 所在:
    例如:
    pm path com.TDiJoy.fane
    package:/mnt/asec/com.TDiJoy.fane-1/pkg.apk

  6. 安装APK:
    pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH

    PATH 指 APK文件绝对路径和文件名。

    例如:
    pm install /data/3dijoy_fane.apk

    这几个参数很有用:

     -r: 安装一个已经安装的APK,保持其数据不变。
     -i:指定安装的包名。(没试出来)
     -s: 安装到SDCard上。
     -f: 安装到内部Flash上。
    
  7. 卸载APK:
    pm uninstall 包名。
    这里注意一定是包名!包名可以使用pm list package获得。
    例如:
    pm uninstall com.TDiJoy.fane

  8. 得到和设置缺省安装位置:
    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

    pm getInstallLocation
    得到缺省的安装位置。

    设置:
    pm setInstallLocation <0|1|2>

    0: 自动。
    1:内部Flash。
    2:扩展存储设备。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ʚ兔子的先森ɞ

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值