Android pm命令詳解

來源:互聯網
上載者:User

Android pm命令詳解

在看相關PackageManager代碼時,無意中發現Android 下提供一個pm命令,通常放在/system/bin/下。這個命令與Package有關,且非常實用。所以研究之。

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

1. 具體使用方法:

1.1:察看已安裝的包:
pm list package
此時則顯示所有已經安裝的包名。

pm list package -f
也顯示associated檔案所在目錄(即儲存的APK檔案)

1.2:察看已知的許可權組:
pm list permission-groups

1.3:察看所有已知的許可權:
pm list permissions

1.4:列出所有硬體相關資訊:
pm list features

結果通常類似:
feature:reqGlEsVersion=0x20000
feature:android.hardware.bluetooth
feature:android.hardware.camera
feature:android.hardware.location
feature:android.hardware.location.network
feature:android.hardware.microphone
feature:android.hardware.sensor.accelerometer
feature:android.hardware.sensor.compass
feature:android.hardware.touchscreen
feature:android.hardware.wifi

1.5:列出指定包名的 associated 檔案 (APK封存檔案) 所在:
例如:
pm path com.TDiJoy.fane
package:/mnt/asec/com.TDiJoy.fane-1/pkg.apk

1.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上。

1.7:卸載APK:
pm uninstall 包名。
例如:
pm uninstall com.TDiJoy.fane

1.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:擴充存放裝置。

執行個體:如何在海信2.2 STB上將APK安裝到隨身碟中:
Sam首先嘗試使用:
pm setInstallLocation 2
之後安裝之,沒有用。

後來做如下嘗試:
*在其它設定->存放裝置->制定預設存放裝置中選擇隨身碟為預設存放裝置。
# pm install -s xxxx.apk*

就可以成功。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.