您的位置:首页 > 产品设计 > 产品经理

pm(pakacge manager)命令

2016-06-29 11:23 701 查看
1、先把官方文档撸下来,咱们慢慢分解,我简单翻译翻译啊……

Using package manager (pm) 使用package manager

Within an adb shell, you can issue commands with the package manager (
pm
) tool to perform actions and queries on application packages installed on the device. While in a shell, the syntax is: 
pm <command>


You can also issue a package manager command directly from adb without entering a remote shell. For example:
adb shell pm uninstall com.example.MyApp


Table 3. Available package manager commands.
CommandDescription
list packages [options] <FILTER>
Prints all packages, optionally only those whose package name contains the text in
<FILTER>
.
Options: //打印所有包信息,你可以把文本在放到<FILTER>过滤,包含过滤的内容会被检索出来,很方便
-f
: See their associated file. 
-d
: Filter to only show disabled packages.
-e
: Filter to only show enabled packages.
-s
: Filter to only show system packages. 只显示系统app的包名
-3
: Filter to only show third party packages.
-i
: See the installer for the packages.
-u
: Also include uninstalled packages.
--user <USER_ID>
: The user space to query.
list permission-groups
Prints all known permission groups.
list permissions [options] <GROUP>
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.
list instrumentation
List all test packages.
Options:
-f
: List the APK file for the test package.
<TARGET_PACKAGE>
: List test packages for only this app.
list features
Prints all features of the system.
list libraries
Prints all the libraries supported by the current device.
list users
Prints all users on the system.
path <PACKAGE>
Print the path to the APK of the given 
<PACKAGE>
.
install [options] <PATH>
Installs a package (specified by 
<PATH>
) 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 <INSTALLER_PACKAGE_NAME>
: Specify the installer package name.
-s
: Install package on the shared mass storage (such as sdcard).
-f
: Install package on the internal system memory.
-d
: Allow version code downgrade.
-g
: Grant all permissions listed in the app manifest.
uninstall [options] <PACKAGE>
Removes a package from the system.
Options:
-k
: Keep the data and cache directories around after package removal.
clear <PACKAGE>
Deletes all data associated with a package. //删除所有与此包关联的数据
enable <PACKAGE_OR_COMPONENT>
Enable the given package or component (written as "package/class").
disable <PACKAGE_OR_COMPONENT>
Disable the given package or component (written as "package/class").
disable-user [options] <PACKAGE_OR_COMPONENT>
Options:
--user <USER_ID>
: The user to disable.
grant <PACKAGE_NAME> <PERMISSION>
Grant a permission to an app. On devices running Android 6.0 (API level 23) and higher, may be any permission declared in the app manifest. On devices running Android 5.1 (API level 22) and lower, must be an optional permission defined by the app.
revoke <PACKAGE_NAME> <PERMISSION>
Revoke a permission from an app. On devices running Android 6.0 (API level 23) and higher, may be any permission declared in the app manifest. On devices running Android 5.1 (API level 22) and lower, must be an optional permission defined by the app.
set-install-location <LOCATION>
Changes the default install location. Location values:
0
: Auto—Let system decide the best location.
1
: Internal—install on internal device storage.
2
: External—install on external media.

Note: This is only intended for debugging; using this can cause applications to break and other undesireable behavior.
get-install-location
Returns the current install location. Return values:
0 [auto]
: Lets system decide the best location
1 [internal]
: Installs on internal device storage
2 [external]
: Installs on external media
set-permission-enforced <PERMISSION> [true|false]
Specifies whether the given permission should be enforced.
trim-caches <DESIRED_FREE_SPACE>
Trim cache files to reach the given free space.
create-user <USER_NAME>
Create a new user with the given 
<USER_NAME>
, printing the new user identifier of the user.
remove-user <USER_ID>
Remove the user with the given 
<USER_IDENTIFIER>
, deleting all data associated with that user
get-max-users
Prints the maximum number of users supported by the device.
2、上面上来就写一了一个demo

adb shell pm uninstall <packageName>

等同于

adb uninstall <packageName>

3、当然想用pm命令,两种方式均可,我前面肯定有说过

a、第一种,不进入Android的Shell,直接发起命令 adb shell pm <command>
b、第二种,进入Android的shell

adb shell
su
pm <command>

4、要学会看官方文档
其中【】这个字符括起来的,代表是可选参数, <>这个字符括起来的,那一定是必填参数,但是如果不填必填参数,也有效果,往往代表的是all,或者是调起help文档。

5、文档写的挺全的,说几个常用的场景

6、查看调取pm帮助文档,就是这么简单粗暴

pm

7、显示所有安装app的包名
adb shell pm list packages

8、找到包含文本的包名
adb shell pm list packages com.xx

9、清除指定包名的所有本地数据,这个很实用哦
adb shell pm clear <packageName>
10、其它的,好家伙,你文档里看吧,命令high了去了!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: