【Android】判断某个AP是否在系统中存在(PackageManager与PackageInfo)
2011-12-09 16:48
573 查看
【0】我们可以使用
public abstract class
extends Object
Class for retrieving various kinds of information related to the application packages that are currently installed on the device. You can find this class through
【1】使用从Manifest.xml文件中获得到的PackageInfo来取得AP的信息.
public class
extends Object
implements Parcelable
Overall information about the contents of a package. This corresponds to all of the information collected from AndroidManifest.xml.
Since: API Level 1
Since: API Level 1
Array of all
or null if there were none. This is only filled in if the flag
set.
Since: API Level 1
Information collected from the <application> tag, or null if there was none.
Since: API Level 3
Application specified preferred configuration
included under <manifest>, or null if there were none. This is only filled in if the flag
set.
Since: API Level 9
The time at which the app was first installed. Units are as per
Since: API Level 1
All kernel group-IDs that have been assigned to this package. This is only filled in if the flag
set.
Since: API Level 1
Array of all
under <manifest>, or null if there were none. This is only filled in if the flag
set.
Since: API Level 9
The time at which the app was last updated. Units are as per
Since: API Level 1
The name of this package. From the <manifest> tag's "name" attribute.
Since: API Level 1
Array of all
<manifest>, or null if there were none. This is only filled in if the flag
set.
Since: API Level 1
Array of all
or null if there were none. This is only filled in if the flag
set.
Since: API Level 1
Array of all
or null if there were none. This is only filled in if the flag
set.
Since: API Level 5
The features that this application has said it requires.
Since: API Level 1
Array of all
under <manifest>, or null if there were none. This is only filled in if the flag
set. This list includes all permissions requested, even those that were not granted or known by the system at install time.
Since: API Level 1
Array of all
or null if there were none. This is only filled in if the flag
set.
Since: API Level 3
The shared user ID name of this package, as specified by the <manifest> tag's
Since: API Level 3
The shared user ID label of this package, as specified by the <manifest> tag's
Since: API Level 1
Array of all signatures read from the package file. This is only filled in if the flag
set.
Since: API Level 1
The version number of this package, as specified by the <manifest> tag's
Since: API Level 1
The version name of this package, as specified by the <manifest> tag's
【2】使用上面两个类来实现一个判断某个AP是否安装在系统中的工具类
Since: API Level 1
Return a List of all packages that are installed on the device.
Parameters
Returns
A List of PackageInfo objects, one for each package that is installed on the device. In the unlikely case of there being no installed packages, an empty list is returned. If flag GET_UNINSTALLED_PACKAGES is set, a list of all applications including those deleted
with DONT_DELETE_DATA (partially installed apps with data directory) will be returned.
谢谢!
getPackageManager() 方法来查询安装在系统上的AP.
public abstract class
PackageManager
extends Objectjava.lang.Object | |
↳ | android.content.pm.PackageManager |
Known Direct Subclasses MockPackageManager |
getPackageManager().
【1】使用从Manifest.xml文件中获得到的PackageInfo来取得AP的信息.
public class
PackageInfo
extends Objectimplements Parcelable
java.lang.Object | |
↳ | android.content.pm.PackageInfo |
public static final Creator<PackageInfo> CREATOR
Since: API Level 1
public ActivityInfo[] activities
Since: API Level 1Array of all
<activity>tags included under <application>,
or null if there were none. This is only filled in if the flag
GET_ACTIVITIESwas
set.
public ApplicationInfo applicationInfo
Since: API Level 1Information collected from the <application> tag, or null if there was none.
public ConfigurationInfo[] configPreferences
Since: API Level 3Application specified preferred configuration
<uses-configuration>tags
included under <manifest>, or null if there were none. This is only filled in if the flag
GET_CONFIGURATIONSwas
set.
public long firstInstallTime
Since: API Level 9The time at which the app was first installed. Units are as per
currentTimeMillis().
public int[] gids
Since: API Level 1All kernel group-IDs that have been assigned to this package. This is only filled in if the flag
GET_GIDSwas
set.
public InstrumentationInfo[] instrumentation
Since: API Level 1Array of all
<instrumentation>tags included
under <manifest>, or null if there were none. This is only filled in if the flag
GET_INSTRUMENTATIONwas
set.
public long lastUpdateTime
Since: API Level 9The time at which the app was last updated. Units are as per
currentTimeMillis().
public String packageName
Since: API Level 1The name of this package. From the <manifest> tag's "name" attribute.
public PermissionInfo[] permissions
Since: API Level 1Array of all
<permission>tags included under
<manifest>, or null if there were none. This is only filled in if the flag
GET_PERMISSIONSwas
set.
public ProviderInfo[] providers
Since: API Level 1Array of all
<provider>tags included under <application>,
or null if there were none. This is only filled in if the flag
GET_PROVIDERSwas
set.
public ActivityInfo[] receivers
Since: API Level 1Array of all
<receiver>tags included under <application>,
or null if there were none. This is only filled in if the flag
GET_RECEIVERSwas
set.
public FeatureInfo[] reqFeatures
Since: API Level 5The features that this application has said it requires.
public String[] requestedPermissions
Since: API Level 1Array of all
<uses-permission>tags included
under <manifest>, or null if there were none. This is only filled in if the flag
GET_PERMISSIONSwas
set. This list includes all permissions requested, even those that were not granted or known by the system at install time.
public ServiceInfo[] services
Since: API Level 1Array of all
<service>tags included under <application>,
or null if there were none. This is only filled in if the flag
GET_SERVICESwas
set.
public String sharedUserId
Since: API Level 3The shared user ID name of this package, as specified by the <manifest> tag's
sharedUserIdattribute.
public int sharedUserLabel
Since: API Level 3The shared user ID label of this package, as specified by the <manifest> tag's
sharedUserLabelattribute.
public Signature[] signatures
Since: API Level 1Array of all signatures read from the package file. This is only filled in if the flag
GET_SIGNATURESwas
set.
public int versionCode
Since: API Level 1The version number of this package, as specified by the <manifest> tag's
versionCodeattribute.
public String versionName
Since: API Level 1The version name of this package, as specified by the <manifest> tag's
versionNameattribute.
【2】使用上面两个类来实现一个判断某个AP是否安装在系统中的工具类
/** * Whether the AP was installed * @param context:the Context * @param packageName:the ap packageName * @return */ public static boolean isAppInstalled(Context context, String packageName) { //获取到一个PackageManager的instance final PackageManager packageManager = context.getPackageManager(); //PERMISSION_GRANTED = 0 List<PackageInfo> mPackageInfo = packageManager.getInstalledPackages(0); boolean flag = false; if(mPackageInfo != null) { String tempName = null; for(int i = 0; i < mPackageInfo.size(); i++) { //获取到AP包名 tempName = mPackageInfo.get(i).packageName; if(tempName != null && tempName.equals(packageName)) { MyLogger.kLog().i("Package[" + packageName + "]:is installed."); flag = true; break; } } } return flag; }
public abstract List<PackageInfo> getInstalledPackages (int
flags)
Since: API Level 1Return a List of all packages that are installed on the device.
Parameters
flags | Additional option flags. Use any combination of GET_ACTIVITIES, GET_GIDS, GET_CONFIGURATIONS, GET_INSTRUMENTATION, GET_PERMISSIONS, GET_PROVIDERS, GET_RECEIVERS, GET_SERVICES, GET_SIGNATURES, GET_UNINSTALLED_PACKAGESto modify the data returned. |
---|
Returns
A List of PackageInfo objects, one for each package that is installed on the device. In the unlikely case of there being no installed packages, an empty list is returned. If flag GET_UNINSTALLED_PACKAGES is set, a list of all applications including those deleted
with DONT_DELETE_DATA (partially installed apps with data directory) will be returned.
谢谢!
相关文章推荐
- 判断android系统中是否有指定apk存在,并打开
- android&nbsp;判断一个包是否在系统存在
- 利用PackageManager判断系统中是否存在与Intent匹配的组件
- Android中如何判断Intent是否存在
- Android通过签名判断是否系统编译的apk
- android java 判断某张表是否存在
- Android 判断SD卡是否存在及容量查询
- android 判断桌面快捷方式是否存在
- Android.mk如何判断文件是否存在
- Android判断应用或Activity是否存在
- Android 判断SD卡是否存在及容量查询
- android 获取路径目录方法以及判断目录是否存在,创建目录
- Android 判断SD卡是否存在及容量查询
- Android判断手机是否是小米MIUI系统的方法
- Android 判断SD卡是否存在及容量查询
- android 获取路径目录方法以及判断目录是否存在,创建目录
- Linux系统shell脚本判断变量文件目录:权限、是否存在、空值、相等
- android点滴(24)之android 创建、删除、判断是否存在快捷方式
- Android 判断SD卡是否存在及容量查询
- Android 判断Intent是否存在