0

Does anyone know if it is possible to get an applications icon and somehow render it in a html img element in WebView?

For example, in the code below I've been able to get the installed apps and create a JSON file containing the name and package name as strings. Is there a way to get a path for the Drawable that can then be used in my WebView as the 'src' attribute for an image?

PackageManager packageManager = getPackageManager();

Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER);

List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent, 0);
ArrayList<JSONObject> jsonAppList = new ArrayList<>();

for (ResolveInfo resolveInfo : resolveInfoList) {
    JSONObject jsonApp = new JSONObject();
    try {
        Drawable icon = resolveInfo.activityInfo.loadIcon(packageManager);

        jsonApp.put("name", resolveInfo.loadLabel(packageManager).toString());
        jsonApp.put("packageName", resolveInfo.activityInfo.packageName);
        jsonApp.put("icon", icon);

        jsonAppList.add(jsonApp);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

  • Was able to achieve what I needed by doing the following: App icons into drawables: [https://stackoverflow.com/questions/10696121/get-icons-of-all-installed-apps-in-android](https://stackoverflow.com/questions/10696121/get-icons-of-all-installed-apps-in-android) Drawables into bitmaps: [https://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap](https://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap) Bitmap into WebView: https://stackoverflow.com/questions/10849200/android-how-to-display-a-bitmap-in-a-webview – tiwoxa2625 Jul 08 '21 at 07:07

0 Answers0