我正在尝试在Android Studio中构建启动器,并且正在使用RecyclerView
[您知道,安装应用程序后,它将自动添加到启动器菜单中。同样,删除应用程序后,也会将其从视图中删除。
应该使用哪种方法来实现这一目标?现在,每次创建视图时都会更新列表:
public ArrayList<AppInfo> getAppInfo(){
ArrayList <AppInfo> appsList = new ArrayList<>();
PackageManager pm = getPackageManager();
Intent i = new Intent(Intent.ACTION_MAIN, null);
i.addCategory(Intent.CATEGORY_LAUNCHER);
List<ResolveInfo> allApps = pm.queryIntentActivities(i, 0);
for(ResolveInfo ri:allApps) {
AppInfo app = new AppInfo();
app.label = ri.loadLabel(pm);
app.packageName = ri.activityInfo.packageName;
app.icon = ri.activityInfo.loadIcon(pm);
appsList.add(app);
System.out.println(app.label);
}
return appsList;
}
<receiver
android:name="com.your.receiver"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED" />
<action android:name="android.intent.action.PACKAGE_REMOVED" />
<data android:scheme="package"/>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.BROADCAST_PACKAGE_REMOVED" />