package com.example.mobilesafe.engine;
import java.util.ArrayList;
import java.util.List;
import com.example.mobilesafe.bean.AppInfo;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
public class getAppInfoEngine {
public static List<AppInfo> getAppMessageList(Context mc) {
ArrayList<AppInfo> appInfoList = new ArrayList<AppInfo>();
PackageManager pm = mc.getPackageManager();
List<PackageInfo> installedPackages = pm.getInstalledPackages(0);
for (PackageInfo packageInfo : installedPackages) {
// 创建一个应用信息对象
AppInfo appInfo = new AppInfo();
// 得到当前应用信息
ApplicationInfo applicationInfo = packageInfo.applicationInfo;
// 应用名
appInfo.name = applicationInfo.loadLabel(pm).toString();
// 应用图标
appInfo.icon = applicationInfo.loadIcon(pm);
// 应用包名
appInfo.packageName = packageInfo.packageName;
// 是否是系统应用
if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM) {
appInfo.isSystem = true;
} else {
appInfo.isSystem = false;
}
// 是否安装在存储卡
if ((applicationInfo.flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) == ApplicationInfo.FLAG_EXTERNAL_STORAGE) {
appInfo.isSdcard = true;
} else {
appInfo.isSdcard = false;
}
appInfoList.add(appInfo);
}
return appInfoList;
}
}
package com.example.mobilesafe.bean;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
public class AppInfo {
public String name;
public String packageName;
public Drawable icon;
/**
* 是否是系统自带的应用
*/
public boolean isSystem;
/**
* 是否安装在sd卡
*/
public boolean isSdcard;
}