本文整理匯總了Java中android.content.pm.PackageManager.getInstalledPackages方法的典型用法代碼示例。如果您正苦於以下問題:Java PackageManager.getInstalledPackages方法的具體用法?Java PackageManager.getInstalledPackages怎麽用?Java PackageManager.getInstalledPackages使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getInstalledPackages方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getInstalledApp
import android.content.pm.PackageManager; //導入方法依賴的package包/類
public ArrayList<HashMap<String, String>> getInstalledApp(boolean z) {
try {
PackageManager packageManager = this.context.getPackageManager();
List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);
ArrayList<HashMap<String, String>> arrayList = new ArrayList();
for (PackageInfo packageInfo : installedPackages) {
if (z || !isSystemApp(packageInfo)) {
HashMap hashMap = new HashMap();
hashMap.put("pkg", packageInfo.packageName);
hashMap.put("name", packageInfo.applicationInfo.loadLabel(packageManager)
.toString());
hashMap.put("version", packageInfo.versionName);
arrayList.add(hashMap);
}
}
return arrayList;
} catch (Throwable th) {
Ln.w(th);
return new ArrayList();
}
}
示例2: isAvailable
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/** 檢查手機上是否安裝了指定的軟件 */
public static boolean isAvailable(Context context, String packageName) {
// 獲取packagemanager
final PackageManager packageManager = context.getPackageManager();
// 獲取所有已安裝程序的包信息
List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
// 用於存儲所有已安裝程序的包名
List<String> packageNames = new ArrayList<>();
// 從pinfo中將包名字逐一取出,壓入pName list中
if (packageInfos != null) {
for (int i = 0; i < packageInfos.size(); i++) {
String packName = packageInfos.get(i).packageName;
packageNames.add(packName);
}
}
// 判斷packageNames中是否有目標程序的包名,有TRUE,沒有FALSE
return packageNames.contains(packageName);
}
示例3: getComponentInfo
import android.content.pm.PackageManager; //導入方法依賴的package包/類
private static List<PackageInfo> getComponentInfo(Context context,
List<String> maps) {
PackageManager pm = context.getPackageManager();
List<PackageInfo> infos = pm.getInstalledPackages(0);
List<PackageInfo> available = new ArrayList<PackageInfo>();
if ((infos != null) && (infos.size() > 0))
for (PackageInfo info : infos) {
String packName = info.packageName;
if (!TextUtils.isEmpty(packName) && maps.contains(packName)) {
if (packName.equals(Autonavi_Map)) {
if (info.versionCode >= 161)
available.add(info);
} else {
available.add(info);
}
}
}
return available;
}
示例4: isInstalled
import android.content.pm.PackageManager; //導入方法依賴的package包/類
@Override
public boolean isInstalled(Context context) {
if(context == null)
return false;
final PackageManager packageManager = context.getPackageManager();
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
if (pinfo != null) {
for (int i = 0; i < pinfo.size(); i++) {
String pn = pinfo.get(i).packageName;
if (pn.equals("com.tencent.mobileqq")) {
return true;
} else if(pn.equals("com.tencent.qzone")) {
return true;
}
}
}
return false;
}
示例5: hasQQClientAvailable
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 判斷 用戶是否安裝QQ客戶端
*/
public static boolean hasQQClientAvailable(Context context) {
final PackageManager packageManager = context.getPackageManager();
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
if (pinfo != null) {
for (int i = 0; i < pinfo.size(); i++) {
String pn = pinfo.get(i).packageName;
LogUtils.e("pn = " + pn);
if (pn.equalsIgnoreCase("com.tencent.qqlite") || pn.equalsIgnoreCase("com.tencent.mobileqq")) {
return true;
}
}
}
return false;
}
示例6: getPackages
import android.content.pm.PackageManager; //導入方法依賴的package包/類
private static List<PackageInfo> getPackages(Context context) {
if (cachePackageInfo == null) {
PackageManager pm = context.getPackageManager();
cachePackageInfo = pm.getInstalledPackages(0);
}
return new ArrayList<>(cachePackageInfo);
}
示例7: getAllAppsInfo
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取所有已安裝App信息
* <p>{@link #getBean(PackageManager, PackageInfo)}(名稱,圖標,包名,包路徑,版本號,版本Code,是否安裝在SD卡,是否是用戶程序)</p>
* <p>依賴上麵的getBean方法</p>
*
* @param context 上下文
* @return 所有已安裝的AppInfo列表
*/
public static List<AppInfo> getAllAppsInfo(Context context) {
List<AppInfo> list = new ArrayList<>();
PackageManager pm = context.getPackageManager();
// 獲取係統中安裝的所有軟件信息
List<PackageInfo> installedPackages = pm.getInstalledPackages(0);
for (PackageInfo pi : installedPackages) {
if (pi != null) {
list.add(getBean(pm, pi));
}
}
return list;
}
示例8: getPackageNames
import android.content.pm.PackageManager; //導入方法依賴的package包/類
@Override
protected Set<String> getPackageNames(PreventActivity activity) {
Set<String> names = new HashSet<String>();
PackageManager pm = activity.getPackageManager();
for (PackageInfo pkgInfo : pm.getInstalledPackages(0)) {
ApplicationInfo appInfo = pkgInfo.applicationInfo;
if (PackageUtils.canPrevent(pm, appInfo)) {
names.add(appInfo.packageName);
}
}
return names;
}
示例9: isAppInstalled
import android.content.pm.PackageManager; //導入方法依賴的package包/類
public static boolean isAppInstalled(Context context, String packageName) {
final PackageManager packageManager = context.getPackageManager();
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
List<String> pName = new ArrayList<String>();
if (pinfo != null) {
for (int i = 0; i < pinfo.size(); i++) {
String pn = pinfo.get(i).packageName;
pName.add(pn);
}
}
return pName.contains(packageName);
}
示例10: getAppsInfo
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* 獲取所有已安裝App信息
* <p>{@link #getBean(PackageManager, PackageInfo)}(名稱,圖標,包名,包路徑,版本號,版本Code,是否係統應用)</p>
* <p>依賴上麵的getBean方法</p>
*
* @return 所有已安裝的AppInfo列表
*/
public static List<AppInfo> getAppsInfo() {
List<AppInfo> list = new ArrayList<>();
PackageManager pm = Utils.getContext().getPackageManager();
// 獲取係統中安裝的所有軟件信息
List<PackageInfo> installedPackages = pm.getInstalledPackages(0);
for (PackageInfo pi : installedPackages) {
AppInfo ai = getBean(pm, pi);
if (ai == null) continue;
list.add(ai);
}
return list;
}
示例11: isApplicationInstalled
import android.content.pm.PackageManager; //導入方法依賴的package包/類
boolean isApplicationInstalled(Context context, String packageName) {
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> list = packageManager.getInstalledPackages(0);
for (int i = 0; i < list.size(); i++) {
if (list.get(i).packageName.equalsIgnoreCase(packageName)) {
return true;
}
}
return false;
}
示例12: isInstalled
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* Checks if the app has been installed on the system.
* @param packageManager PackageManager to use.
* @param packageName Name of the package to check.
* @return True if the PackageManager reports that the app is installed, false otherwise.
*/
public static boolean isInstalled(PackageManager packageManager, String packageName) {
List<PackageInfo> packs = packageManager.getInstalledPackages(0);
for (int i = 0; i < packs.size(); i++) {
if (TextUtils.equals(packs.get(i).packageName, packageName)) return true;
}
return false;
}
示例13:
import android.content.pm.PackageManager; //導入方法依賴的package包/類
private boolean Ɨ(Context context, String packageName)
{
final PackageManager packageManager = context.getPackageManager();
List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
for (int i = 0; i < pinfo.size(); i++)
{
if (pinfo.get(i).packageName.equalsIgnoreCase(packageName))
return true;
}
return false;
}
示例14: getAppList
import android.content.pm.PackageManager; //導入方法依賴的package包/類
public static List<AppInfo> getAppList(Context context) {
List<AppInfo> list = new ArrayList<AppInfo>();// 聲明並實例化1個集合
PackageManager pm = context.getPackageManager();//獲取包管理者
List<PackageInfo> pList = pm.getInstalledPackages(0);// 獲取所有的應用程序集合
// 循環遍曆
for (int i = 0; i < pList.size(); i++) {
PackageInfo packageInfo = pList.get(i);// 獲取每一個應用的信息
if (isThirdPartyApp(packageInfo.applicationInfo)
// 不能包含本應用(不刪除自己)
&& !packageInfo.packageName.equals(context.getPackageName())) {
// 從右邊裝到左邊
AppInfo appInfo = new AppInfo();
appInfo.packageName = packageInfo.packageName;
appInfo.versionName = packageInfo.versionName;
appInfo.versionCode = packageInfo.versionCode;
appInfo.firstInstallTime = packageInfo.firstInstallTime;
appInfo.lastUpdateTime = packageInfo.lastUpdateTime;
// 程序名稱
appInfo.appName = ((String) packageInfo.applicationInfo.loadLabel(pm)).trim();
// 過渡
appInfo.applicationInfo = packageInfo.applicationInfo;
// 這行代碼在運行時解除注釋
//appInfo.icon = packageInfo.applicationInfo.loadIcon(pm);
// 計算應用的空間
//publicSourceDir 是app的安裝路徑(文件夾)
String dir = packageInfo.applicationInfo.publicSourceDir;
long byteSize = new File(dir).length();
appInfo.byteSize = byteSize;// 1024*1024 Byte字節
appInfo.size = getSize(byteSize);// 1MB
list.add(appInfo);// 添加到集合
}// if
}
return list;
}
示例15: getAllApp
import android.content.pm.PackageManager; //導入方法依賴的package包/類
String getAllApp(boolean isOnlyGetPackageName)
{
String ret = "";
PackageManager pm = getPackageManager();
List<PackageInfo> ls = pm.getInstalledPackages(0);
for (int i=0;i < ls.size();i++)
{
PackageInfo pi=ls.get(i);
if (!isOnlyGetPackageName)
{
if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
{
ret += "一般應用\n";
}
else
{
ret += "係統應用\n";
}
}
if (!isOnlyGetPackageName)
{
ret += pi.applicationInfo.loadLabel(pm).toString() + "\n" + pi.packageName + "\n\n";
}
else
{
ret += pi.packageName + "\n";
}
}
return ret;
}