I am able to use an intent filter to gather a list of all installed launchers. The trouble is pulling out an int reference to the app icon. The code below catches a NameNotFoundException error.
public RemoteViews getViewAt(int position) {
PackageManager pm = mContext.getPackageManager();
Intent i = new Intent("android.intent.action.MAIN");
i.addCategory("android.intent.category.HOME");
List<ResolveInfo> lst = pm.queryIntentActivities(i, 0);
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
if(position < lst.size()) {
try {
ApplicationInfo ai = pm.getApplicationInfo(lst.get(position).activityInfo.name, 0);
int iconId = ai.icon;
rv.setInt(R.id.widget_item, "setBackgroundResource", iconId);
} catch (NameNotFoundException e) {
//Toast.makeText(mContext, "Fail: " + e, Toast.LENGTH_SHORT).show();
Log.d("Error: ", e.toString());
}
}
The issue is with this line:
ApplicationInfo ai = pm.getApplicationInfo(lst.get(position).activityInfo.name, 0);
Does activityInfo.name not return the packagename?