實(shí)體類 AppInfo
public class AppInfo {
public String name;
public String packageName;
public Drawable icon;
public boolean isRom; //true表示安裝在手機(jī)內(nèi)存
public boolean isUser; //true表示用戶應(yīng)用
}
獲取已安裝應(yīng)用列表
public ArrayList<AppInfo> getInstallApps(Context context){
PackageManager pm = context.getPackageManager();
List<PackageInfo> installedPackages = pm.getInstalledPackages(0); //獲取所以已安裝的包
ArrayList<AppInfo> list = new ArrayList<AppInfo>();
for( PackageInfo packageInfo : installedPackages){
AppInfo info = new AppInfo();
String packageName = packageInfo.packageName; //包名
ApplicationInfo applicationInfo = packageInfo.applicationInfo; //應(yīng)用信息
String name = applicationInfo.loadLabel(pm).toString(); //應(yīng)用名稱
Drawable icon = applicationInfo.loadIcon(pm); //應(yīng)用圖標(biāo)
info.name = name;
info.packageName = packageName;
info.icon = icon;
//狀態(tài)機(jī),通過(guò)01狀態(tài)來(lái)表示是否具備某些屬性和功能
int flags = applicationInfo.flags; //獲取應(yīng)用標(biāo)記
if((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo
.FLAG_EXTERNAL_STORAGE){
//安裝在sdcard
info.isRom = false;
}else{
//安裝在手機(jī)
info.isRom = true;
}
if((flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo
.FLAG_SYSTEM){
//系統(tǒng)應(yīng)用
info.isUser = false;
}else{
//用戶應(yīng)用
info.isUser = true;
}
list.add(info);
}
return list;
}
最后編輯于 :2017.12.10 00:16:54
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者