Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting Icons of applications running on device

I have a list activity which display all running applications in the device. it's displaying a default icon for all application . but I need to get actual application Icon for each application in the list.

public class ApplicationList extends ListActivity {
DataHelper dh;
ImageView vi;
private Drawable icon;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.applist);
    dh = new DataHelper(getApplicationContext());

    PackageManager pm = this.getPackageManager();

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

    Log.d("Test1", "INSERTING APP LIST TO SERVER DB");
     List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED);
     ArrayList<String> applist = new ArrayList<String>();

     for(ResolveInfo rInfo: list){

        applist.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString() );
    }


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            R.layout.installedapp, R.id.textView1, applist);
    setListAdapter(adapter);
}

How to get the icon of other applications (Android) I tried this link but I did not get things solved. so can any one help me out. thanks!

like image 277
thej Avatar asked Mar 30 '12 04:03

thej


2 Answers

try like this

List<PackageInfo> packs = getPackageManager().getInstalledPackages(0);
 Drawable[] icons=new Drawable[packs.size];
for(int i=0;i<packs.size();i++) {
    PackageInfo p = packs.get(i);
    icons[i]= p.applicationInfo.loadIcon(getPackageManager());
 }
like image 110
5hssba Avatar answered Nov 15 '22 06:11

5hssba


try this:

Icon icon = p.applicationInfo.loadIcon(getPackageManager());
imageView.setImageDrawable(icon);
like image 37
Mikonos Avatar answered Nov 15 '22 06:11

Mikonos