SystemUtils.java工具類
package com.techrare.utils;
import java.util.ArrayList;
import java.util.List;
import Android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
/**
* 獲取手機應用信息
* @author Administrator
*
*/
public class SystemUtils {
/**
* 查詢手機內所有應用包括系統應用
* @param context
*/
public static List<PackageInfo> getAllApps(Context context) {
PackageManager pManager = context.getPackageManager();
//獲取手機內所有應用
List<PackageInfo> paklist = pManager.getInstalledPackages(0);
return paklist;
}
/**
* 查詢手機內非系統應用
* @param context
* @return
*/
public static List<PackageInfo> getAllAppsNoSystem(Context context) {
List<PackageInfo> apps = new ArrayList<PackageInfo>();
PackageManager pManager = context.getPackageManager();
//獲取手機內所有應用
List<PackageInfo> paklist = pManager.getInstalledPackages(0);
for (int i = 0; i < paklist.size(); i++) {
PackageInfo pak = (PackageInfo) paklist.get(i);
//判斷是否為非系統預裝的應用程序
if ((pak.applicationInfo.flags & pak.applicationInfo.FLAG_SYSTEM) <= 0) {
// customs applications
apps.add(pak);
}
}
return apps;
}
/**
* 查詢手機內所有支持分享的應用
* @param context
* @return
*/
public static List<ResolveInfo> getShareApps(Context context){
List<ResolveInfo> mApps = new ArrayList<ResolveInfo>();
Intent intent=new Intent(Intent.ACTION_SEND,null);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("text/plain");
PackageManager pManager = context.getPackageManager();
mApps = pManager.queryIntentActivities(intent,PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
return mApps;
}
/* 備注:
通過 PackageInfo 獲取具體信息方法:
包名獲取方法:packageInfo.packageName
icon獲取獲取方法:packageManager.getApplicationIcon(applicationInfo)
應用名稱獲取方法:packageManager.getApplicationLabel(applicationInfo)
使用權限獲取方法:packageManager.getPackageInfo(packageName,PackageManager.GET_PERMISSIONS).requestedPermissions
通過 ResolveInfo 獲取具體信息方法:
包名獲取方法:resolve.activityInfo.packageName
icon獲取獲取方法:resolve.loadIcon(packageManager)
應用名稱獲取方法:resolve.loadLabel(packageManager).toString()
*/
}
更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11