Getting icons of applications running on a device

I have a list activity that displays all running applications on the device. It displays the default icon for all applications. but I need to get a real 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 understand anything. so can someone help me. thank!

+5
source share
3 answers

try it

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());
 }
+7
source

try the following:

Icon icon = p.applicationInfo.loadIcon(getPackageManager());
imageView.setImageDrawable(icon);
+4
source

packageinformation:

PackageInformation {

private Context mContext;

public  PackageInformation(Context context){
    mContext=context;   
}


class InfoObject {
public String appname = "";
public String pname = "";
public String versionName = "";
public int versionCode = 0;
public Drawable icon;


public void InfoObjectAggregatePrint() {//not used yet
    Log.v(appname,appname + "\t" + pname + "\t" + versionName + "\t" + versionCode);
}

}      private ArrayList getPackages() {        ArrayList apps = getInstalledApps (false);/* false = */   final int max = apps.size();    (int = 0; i

 public ArrayList<InfoObject> getInstalledApps(boolean getSysPackages) {
ArrayList<InfoObject> res = new ArrayList<InfoObject>();        
List<PackageInfo> packs = mContext.getPackageManager().getInstalledPackages(0);
for(int i=0;i<packs.size();i++) {
    PackageInfo p = packs.get(i);
    if ((!getSysPackages) && (p.versionName == null)) {
        continue ;
    }
    InfoObject newInfo = new InfoObject();
    newInfo.appname = p.applicationInfo.loadLabel(mContext.getPackageManager()).toString();
    newInfo.pname = p.packageName;
    newInfo.versionName = p.versionName;
    newInfo.versionCode = p.versionCode;
    newInfo.icon = p.applicationInfo.loadIcon(mContext.getPackageManager());
    res.add(newInfo);
}
return res; 
 }


 }

remove it somewhere and now to access information from your Activity working class do the following:

  PackageInformation androidPackagesInfo=new PackageInformation(this);      
    ArrayList<InfoObject> appsData=androidPackagesInfo.getInstalledApps(true);


for (InfoObject info : appsData) {


            Toast.makeText(MainActivity.this, info.appname,2).show();
                Drawable somedrawable=info.icon;

}

0
source

All Articles