public class PackageUtils
extends java.lang.Object
installNormal(android.content.Context, String)
installSilent(android.content.Context, String)
install(android.content.Context, String)
uninstallNormal(android.content.Context, String)
uninstallSilent(android.content.Context, String)
uninstall(android.content.Context, String)
isSystemApplication(android.content.Context)
isSystemApplication(android.content.Context, String)
isSystemApplication(android.content.pm.PackageManager, String)
getInstallLocation()
get system install locationisTopActivity(android.content.Context, String)
whether the app whost package's name is packageName is on the
top of the stackstartInstalledAppDetails(android.content.Context, String)
start InstalledAppDetails Activity限定符和类型 | 字段和说明 |
---|---|
static int |
APP_INSTALL_AUTO
App installation location settings values, same to
APP_INSTALL_AUTO |
static int |
APP_INSTALL_EXTERNAL |
static int |
APP_INSTALL_INTERNAL |
static int |
DELETE_FAILED_DEVICE_POLICY_MANAGER
Uninstall return code
uninstall fail if the system failed to delete the package because it is the active DevicePolicy manager. |
static int |
DELETE_FAILED_INTERNAL_ERROR
Uninstall return code
uninstall fail if the system failed to delete the package for an unspecified reason. |
static int |
DELETE_FAILED_INVALID_PACKAGE
Uninstall return code
uninstall fail if pcakge name is invalid |
static int |
DELETE_FAILED_PERMISSION_DENIED
Uninstall return code
uninstall fail if permission denied |
static int |
DELETE_SUCCEEDED
Uninstall return code
uninstall success. |
static int |
INSTALL_FAILED_ALREADY_EXISTS
Installation return code
the package is already installed. |
static int |
INSTALL_FAILED_CONFLICTING_PROVIDER
Installation return code
the new package failed because it contains a content provider with the same authority as a provider already installed in the system. |
static int |
INSTALL_FAILED_CONTAINER_ERROR
Installation return code
a secure container mount point couldn't be accessed on external media. |
static int |
INSTALL_FAILED_CPU_ABI_INCOMPATIBLE
Installation return code
the package being installed contains native code, but none that is compatible with the the device's CPU_ABI. |
static int |
INSTALL_FAILED_DEXOPT
Installation return code
the new package failed while optimizing and validating its dex files, either because there was not enough storage or the validation failed. |
static int |
INSTALL_FAILED_DUPLICATE_PACKAGE
Installation return code
a package is already installed with the same name. |
static int |
INSTALL_FAILED_INSUFFICIENT_STORAGE
Installation return code
the package manager service found that the device didn't have enough storage space to install the app. |
static int |
INSTALL_FAILED_INTERNAL_ERROR
Installation return code
if the system failed to install the package because of system issues. |
static int |
INSTALL_FAILED_INVALID_APK
Installation return code
the package archive file is invalid. |
static int |
INSTALL_FAILED_INVALID_INSTALL_LOCATION
Installation return code
the new package couldn't be installed in the specified install location. |
static int |
INSTALL_FAILED_INVALID_URI
Installation return code
the URI passed in is invalid. |
static int |
INSTALL_FAILED_MEDIA_UNAVAILABLE
Installation return code
the new package couldn't be installed in the specified install location because the media is not available. |
static int |
INSTALL_FAILED_MISSING_FEATURE
Installation return code
the new package uses a feature that is not available. |
static int |
INSTALL_FAILED_MISSING_SHARED_LIBRARY
Installation return code
the new package uses a shared library that is not available. |
static int |
INSTALL_FAILED_NEWER_SDK
Installation return code
the new package failed because the current SDK version is newer than that required by the package. |
static int |
INSTALL_FAILED_NO_SHARED_USER
Installation return code
the requested shared user does not exist. |
static int |
INSTALL_FAILED_OLDER_SDK
Installation return code
the new package failed because the current SDK version is older than that required by the package. |
static int |
INSTALL_FAILED_OTHER
Installation return code
other reason |
static int |
INSTALL_FAILED_PACKAGE_CHANGED
Installation return code
the package changed from what the calling program expected. |
static int |
INSTALL_FAILED_REPLACE_COULDNT_DELETE
Installation return code
the new package uses a shared library that is not available. |
static int |
INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
Installation return code
the new package is requested a shared user which is already installed on the device and does not have matching signature. |
static int |
INSTALL_FAILED_TEST_ONLY
Installation return code
the new package failed because it has specified that it is a test-only package and the caller has not supplied the INSTALL_FAILED_TEST_ONLY flag. |
static int |
INSTALL_FAILED_UID_CHANGED
Installation return code
the new package is assigned a different UID than it previously held. |
static int |
INSTALL_FAILED_UPDATE_INCOMPATIBLE
Installation return code
a previously installed package of the same name has a different signature than the new package (and the old package's data was not removed). |
static int |
INSTALL_FAILED_VERIFICATION_FAILURE
Installation return code
the new package couldn't be installed because the verification did not succeed. |
static int |
INSTALL_FAILED_VERIFICATION_TIMEOUT
Installation return code
the new package couldn't be installed because the verification timed out. |
static int |
INSTALL_PARSE_FAILED_BAD_MANIFEST
Installation return code
if the parser was unable to retrieve the AndroidManifest.xml file. |
static int |
INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME
Installation return code
if the parser encountered a bad or missing package name in the manifest. |
static int |
INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID
Installation return code
if the parser encountered a bad shared user id name in the manifest. |
static int |
INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING
Installation return code
if the parser encountered a CertificateEncodingException in one of the files in the .apk. |
static int |
INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES
Installation return code
if the parser found inconsistent certificates on the files in the .apk. |
static int |
INSTALL_PARSE_FAILED_MANIFEST_EMPTY
Installation return code
if the parser did not find any actionable tags (instrumentation or application) in the manifest. |
static int |
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
Installation return code
if the parser encountered some structural problem in the manifest. |
static int |
INSTALL_PARSE_FAILED_NO_CERTIFICATES
Installation return code
if the parser did not find any certificates in the .apk. |
static int |
INSTALL_PARSE_FAILED_NOT_APK
Installation return code
if the parser was given a path that is not a file, or does not end with the expected '.apk' extension. |
static int |
INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
Installation return code
if the parser encountered an unexpected exception. |
static int |
INSTALL_SUCCEEDED
Installation return code
install success. |
static java.lang.String |
TAG |
构造器和说明 |
---|
PackageUtils() |
限定符和类型 | 方法和说明 |
---|---|
static int |
getAppVersionCode(android.content.Context context)
get app version code
|
static int |
getInstallLocation()
get system install location
can be set by System Menu Setting->Storage->Prefered install location |
static int |
install(android.content.Context context,
java.lang.String filePath)
install according conditions
if system application or rooted, see
installSilent(android.content.Context, String)
else see installNormal(android.content.Context, String)
|
static boolean |
installNormal(android.content.Context context,
java.lang.String filePath)
install package normal by system intent
|
static int |
installSilent(android.content.Context context,
java.lang.String filePath)
install package silent by root
Attentions:
Don't call this on the ui thread, it may costs some times.
|
static int |
installSilent(android.content.Context context,
java.lang.String filePath,
java.lang.String pmParams)
install package silent by root
Attentions:
Don't call this on the ui thread, it may costs some times.
|
static boolean |
isSystemApplication(android.content.Context context)
whether context is system application
|
static boolean |
isSystemApplication(android.content.Context context,
java.lang.String packageName)
whether packageName is system application
|
static boolean |
isSystemApplication(android.content.pm.PackageManager packageManager,
java.lang.String packageName)
whether packageName is system application
|
static java.lang.Boolean |
isTopActivity(android.content.Context context,
java.lang.String packageName)
whether the app whost package's name is packageName is on the top of the stack
Attentions:
You should add android.permission.GET_TASKS in manifest
|
static void |
startInstalledAppDetails(android.content.Context context,
java.lang.String packageName)
start InstalledAppDetails Activity
|
static int |
uninstall(android.content.Context context,
java.lang.String packageName)
uninstall according conditions
if system application or rooted, see
uninstallSilent(android.content.Context, String)
else see uninstallNormal(android.content.Context, String)
|
static boolean |
uninstallNormal(android.content.Context context,
java.lang.String packageName)
uninstall package normal by system intent
|
static int |
uninstallSilent(android.content.Context context,
java.lang.String packageName)
uninstall package and clear data of app silent by root
|
static int |
uninstallSilent(android.content.Context context,
java.lang.String packageName,
boolean isKeepData)
uninstall package silent by root
Attentions:
Don't call this on the ui thread, it may costs some times.
|
public static final java.lang.String TAG
public static final int APP_INSTALL_AUTO
APP_INSTALL_AUTO
public static final int APP_INSTALL_INTERNAL
public static final int APP_INSTALL_EXTERNAL
public static final int INSTALL_SUCCEEDED
public static final int INSTALL_FAILED_ALREADY_EXISTS
public static final int INSTALL_FAILED_INVALID_APK
public static final int INSTALL_FAILED_INVALID_URI
public static final int INSTALL_FAILED_INSUFFICIENT_STORAGE
public static final int INSTALL_FAILED_DUPLICATE_PACKAGE
public static final int INSTALL_FAILED_NO_SHARED_USER
public static final int INSTALL_FAILED_UPDATE_INCOMPATIBLE
public static final int INSTALL_FAILED_SHARED_USER_INCOMPATIBLE
public static final int INSTALL_FAILED_MISSING_SHARED_LIBRARY
public static final int INSTALL_FAILED_REPLACE_COULDNT_DELETE
public static final int INSTALL_FAILED_DEXOPT
public static final int INSTALL_FAILED_OLDER_SDK
public static final int INSTALL_FAILED_CONFLICTING_PROVIDER
public static final int INSTALL_FAILED_NEWER_SDK
public static final int INSTALL_FAILED_TEST_ONLY
INSTALL_FAILED_TEST_ONLY
flag.public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE
public static final int INSTALL_FAILED_MISSING_FEATURE
public static final int INSTALL_FAILED_CONTAINER_ERROR
public static final int INSTALL_FAILED_INVALID_INSTALL_LOCATION
public static final int INSTALL_FAILED_MEDIA_UNAVAILABLE
public static final int INSTALL_FAILED_VERIFICATION_TIMEOUT
public static final int INSTALL_FAILED_VERIFICATION_FAILURE
public static final int INSTALL_FAILED_PACKAGE_CHANGED
public static final int INSTALL_FAILED_UID_CHANGED
public static final int INSTALL_PARSE_FAILED_NOT_APK
public static final int INSTALL_PARSE_FAILED_BAD_MANIFEST
public static final int INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION
public static final int INSTALL_PARSE_FAILED_NO_CERTIFICATES
public static final int INSTALL_PARSE_FAILED_INCONSISTENT_CERTIFICATES
public static final int INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING
public static final int INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME
public static final int INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID
public static final int INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
public static final int INSTALL_PARSE_FAILED_MANIFEST_EMPTY
public static final int INSTALL_FAILED_INTERNAL_ERROR
public static final int INSTALL_FAILED_OTHER
public static final int DELETE_SUCCEEDED
public static final int DELETE_FAILED_INTERNAL_ERROR
public static final int DELETE_FAILED_DEVICE_POLICY_MANAGER
public static final int DELETE_FAILED_INVALID_PACKAGE
public static final int DELETE_FAILED_PERMISSION_DENIED
public static final int install(android.content.Context context, java.lang.String filePath)
installSilent(android.content.Context, String)
installNormal(android.content.Context, String)
context
- filePath
- public static boolean installNormal(android.content.Context context, java.lang.String filePath)
context
- filePath
- file path of packagepublic static int installSilent(android.content.Context context, java.lang.String filePath)
context
- filePath
- file path of packageINSTALL_SUCCEEDED
means install success, other means failed. details see
PackageUtils
.INSTALL_FAILED_*. same to PackageManager
.INSTALL_*installSilent(android.content.Context, String, String)
public static int installSilent(android.content.Context context, java.lang.String filePath, java.lang.String pmParams)
context
- filePath
- file path of packagepmParams
- pm install paramsINSTALL_SUCCEEDED
means install success, other means failed. details see
PackageUtils
.INSTALL_FAILED_*. same to PackageManager
.INSTALL_*public static final int uninstall(android.content.Context context, java.lang.String packageName)
uninstallSilent(android.content.Context, String)
uninstallNormal(android.content.Context, String)
context
- packageName
- package name of apppublic static boolean uninstallNormal(android.content.Context context, java.lang.String packageName)
context
- packageName
- package name of apppublic static int uninstallSilent(android.content.Context context, java.lang.String packageName)
context
- packageName
- package name of appuninstallSilent(android.content.Context, String, boolean)
public static int uninstallSilent(android.content.Context context, java.lang.String packageName, boolean isKeepData)
context
- file path of packagepackageName
- package name of appisKeepData
- whether keep the data and cache directories around after package removalDELETE_SUCCEEDED
means uninstall successDELETE_FAILED_INTERNAL_ERROR
means internal errorDELETE_FAILED_INVALID_PACKAGE
means package name errorDELETE_FAILED_PERMISSION_DENIED
means permission deniedpublic static boolean isSystemApplication(android.content.Context context)
context
- public static boolean isSystemApplication(android.content.Context context, java.lang.String packageName)
context
- packageName
- public static boolean isSystemApplication(android.content.pm.PackageManager packageManager, java.lang.String packageName)
packageManager
- packageName
- public static java.lang.Boolean isTopActivity(android.content.Context context, java.lang.String packageName)
context
- packageName
- public static int getAppVersionCode(android.content.Context context)
context
- public static int getInstallLocation()
com.marshalchen.common.commonUtils.fileUtils.PackageUtils#getInstallLocation()}
public static void startInstalledAppDetails(android.content.Context context, java.lang.String packageName)
context
- packageName
-