I made a custom launcher and using this method to retrieve list of applications in my device:
public class myThread extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... Params) {
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.activityName = ri.activityInfo.name;
app.icon = ri.activityInfo.loadIcon(pm);
adapter.addApp(app);
}
return "Success";
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Collections.sort(adapter.getAppsList(),new ActivityNameComparator());
updateStuff();
}
The task is executed in the main activity onCreate()
Opening this launcher when the phone is on gives no issue. I got all applications in both internal storage and SD card.
The issue comes when I reboot my device. There is some applications that lost from the list. I then realized that those applications are those which are saved in my SD Card.
Are there any way to get apps in SD card after rebooting? Or is there a better approach to get applications list for custom launcher?