本文主要是介绍Android开发获取开机启动项列表,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
代码如下:
public class BootStartUtils {
private static final String BOOT_START_PERMISSION =
"android.permission.RECEIVE_BOOT_COMPLETED";
private Context mContext;
public BootStartUtils(Context context) {
mContext = context;
}
/**
* 获取Android开机启动列表
*/
public List<Map<String, Object>> fetchInstalledApps() {
PackageManager pm = mContext.getPackageManager();
List<ApplicationInfo> appInfo = pm.getInstalledApplications(0);
Iterator<ApplicationInfo> appInfoIterator = appInfo.iterator();
List<Map<String, Object>> appList = new ArrayList<Map<String, Object>>(appInfo.size());
while (appInfoIterator.hasNext()) {
ApplicationInfo app = appInfoIterator.next();
int flag = pm.checkPermission(
BOOT_START_PERMISSION, app.packageName);
if (flag == PackageManager.PERMISSION_GRANTED) {
Map<String, Object> appMap = new HashMap<String, Object>();
String label = pm.getApplicationLabel(app).toString();
Drawable icon = pm.getApplicationIcon(app);
String desc = app.packageName;
appMap.put("label", label);
appMap.put("icon", icon);
appMap.put("desc", desc);
appList.add(appMap);
}
}
return appList;
}
原文地址:点击打开链接
这篇关于Android开发获取开机启动项列表的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!