androiduribitmapdrawable

How to retrieve URI or ID from BitmapDrawable


I would like to display names and icons of every installed apps. To do this, I'm retrieving informations with this code :

List<PackageInfo> apps = getPackageManager().getInstalledPackages(0);
ArrayList<AppInfo> res = new ArrayList<>();
for(int i=0;i<apps.size();i++) {
    PackageInfo p = apps.get(i);
    if((p.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0){
        AppInfo newInfo = new AppInfo();
        newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString();
        newInfo.pname = p.packageName;
        newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());
        res.add(newInfo);
    }
}

I already have a custom ListView to display icon and app name, but for icon I need an ID or URI.

newInfo.icon = p.applicationInfo.loadIcon(getPackageManager());

It gives me something like:

android.graphics.drawable.BitmapDrawable@[numbers+letters]" (e.g. android.graphics.drawable.BitmapDrawable@803da37)

and I don't know how to use this.

Is there a way to retrieve URI or ID from this data ?

Someone posted a question about this BitmapDrawable @... here but there is no answer.

EDIT : Actually, I am stocking datas with a HashMap<String, String>, so I have something like :

map.put("name",p.applicationInfo.loadLabel(getPackageManager()).toString());
map.put("img", p.applicationInfo.loadIcon(getPackageManager()).toString());

Then, I use a SimpleAdapter :

myListView = (ListView) findViewById(R.id.customListView);
SimpleAdapter myAdapter = new SimpleAdapter(this.getBaseContext(),listApp,R.layout.myLayout,
        new String[]{"img","name"},new int[]{R.id.img,R.id.name});
myListView.setAdapter(myAdapter);

I know it is not a good idea to use HashMap<String, String> but I don't know how to do it differently.


Solution

  • p.applicationInfo.loadIcon(getPackageManager()); is a right way of retrieving drawable for appliacation/package icons. Please check the way u display it. I suspect that area is having some issues.