【Android】判斷某個AP是否在系統中存在(PackageManager與PackageInfo)
【0】我們可以使用getPackageManager()
方法來查詢安裝在系統上的AP.
java.lang.Object | |
↳ | android.content.pm.PackageManager |
Known Direct Subclasses |
getPackageManager()
.
java.lang.Object | |
↳ | android.content.pm.PackageInfo |
Overall information about the contents of a package. This corresponds to all of the information collected from AndroidManifest.xml.
publicActivityInfo[]activities
Array of all<activity>
tags included under <application>,
or null if there were none. This is only filled in if the flagGET_ACTIVITIES
was
set.
publicApplicationInfoapplicationInfo
Information collected from the <application> tag, or null if there was none.
publicConfigurationInfo[]configPreferences
Application specified preferred configuration<uses-configuration>
tags
included under <manifest>, or null if there were none. This is only filled in if the flagGET_CONFIGURATIONS
was
set.
public longfirstInstallTime
The time at which the app was first installed. Units are as percurrentTimeMillis()
.
public int[]gids
All kernel group-IDs that have been assigned to this package. This is only filled in if the flagGET_GIDS
was
set.
publicInstrumentationInfo[]instrumentation
Array of all<instrumentation>
tags included
under <manifest>, or null if there were none. This is only filled in if the flagGET_INSTRUMENTATION
was
set.
public longlastUpdateTime
The time at which the app was last updated. Units are as percurrentTimeMillis()
.
publicStringpackageName
The name of this package. From the <manifest> tag's "name" attribute.
publicPermissionInfo[]permissions
Array of all<permission>
tags included under
<manifest>, or null if there were none. This is only filled in if the flagGET_PERMISSIONS
was
set.
publicProviderInfo[]providers
Array of all<provider>
tags included under <application>,
or null if there were none. This is only filled in if the flagGET_PROVIDERS
was
set.
publicActivityInfo[]receivers
Array of all<receiver>
tags included under <application>,
or null if there were none. This is only filled in if the flagGET_RECEIVERS
was
set.
publicFeatureInfo[]reqFeatures
The features that this application has said it requires.
publicString[]requestedPermissions
Array of all<uses-permission>
tags included
under <manifest>, or null if there were none. This is only filled in if the flagGET_PERMISSIONS
was
set. This list includes all permissions requested, even those that were not granted or known by the system at install time.
publicServiceInfo[]services
Array of all<service>
tags included under <application>,
or null if there were none. This is only filled in if the flagGET_SERVICES
was
set.
publicStringsharedUserId
The shared user ID name of this package, as specified by the <manifest> tag'ssharedUserId
attribute.
public intsharedUserLabel
The shared user ID label of this package, as specified by the <manifest> tag'ssharedUserLabel
attribute.
publicSignature[]signatures
Array of all signatures read from the package file. This is only filled in if the flagGET_SIGNATURES
was
set.
public intversionCode
The version number of this package, as specified by the <manifest> tag'sversionCode
attribute.
publicStringversionName
The version name of this package, as specified by the <manifest> tag'sversionName
attribute.
/**
* 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 abstractList<PackageInfo>getInstalledPackages(int flags)
Return a List of all packages that are installed on the device.
Parameters
flags |
Additional option flags. Use any combination ofGET_ACTIVITIES ,GET_GIDS ,GET_CONFIGURATIONS ,GET_INSTRUMENTATION ,GET_PERMISSIONS ,GET_PROVIDERS ,GET_RECEIVERS ,GET_SERVICES ,GET_SIGNATURES ,GET_UNINSTALLED_PACKAGES to
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.
謝謝!
相關文章
- JavaScript中判斷是否存在某屬性JavaScript
- js如何判斷頁面中是否存在某個元素JS
- mysql如何判斷是否存在某個欄位MySql
- 如何判斷頁面是否存在某個元素
- sqlserver判斷欄位值是否存在某個字元SQLServer字元
- shell判斷系統路徑中是否存在空格
- Array · 判斷某元素是否在陣列中陣列
- jquery判斷指定元素是否存在於某陣列jQuery陣列
- 儲存過程判斷若個表中是否存在某個名稱的欄位儲存過程
- 如何在js中判斷是否包含某個字串JS字串
- 判斷是否遵守某個協議協議
- 判斷某一個字串是否存在另一個字串中字串
- python中如何判斷list中是否包含某個元素Python
- js如何判斷陣列中是否含有某個元素JS陣列
- jQuery如何判斷一個元素是否存在jQuery
- 如何判斷一個jquery物件是否存在jQuery物件
- javascript判斷一個變數是否存在JavaScript變數
- js如何判斷一個物件是否存在JS物件
- QTP中如何判斷Excel程式是否存在?QTExcel
- 如何判斷一個元素在億級資料中是否存在?
- 41:判斷元素是否存在
- nginx判斷路徑是否含有某個引數做判斷Nginx
- sql 判斷 某列中是否包含 某種符號SQL符號
- PHP 判斷一個字元是否在字串中PHP字元字串
- javascript中檢測某個字串在陣列中是否存在JavaScript字串陣列
- js如何判斷一個函式是否存在JS函式
- jQuery如何判斷某一個元素是否存在jQuery
- jquery判斷元素是否存在於陣列中jQuery陣列
- JavaScript 判斷物件中是否有某屬性JavaScript物件
- 判斷某過程是否在執行的方法
- 用程式碼判斷當前系統是否支援某個版本的feature
- JavaScript 判斷函式是否存在JavaScript函式
- postgresql如何判斷表是否存在SQL
- golang判斷檔案是否存在Golang
- vc判斷檔案是否存在
- jQuery如何判斷元素是否存在jQuery
- iOS判斷是否存在網路iOS
- 如何判斷Javascript物件是否存在JavaScript物件