Joe
Joe

Reputation: 241

How to get the icon of other applications (Android)

What I'm doing is getting a list of all the current running processes on the phone. Which I have done by,

private List<RunningAppProcessInfo> process;
private ActivityManager activityMan;
...
activityMan = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
process = activityMan.getRunningAppProcesses();

this works fine. When I call the processName field like

process.get(i).processName;

I get a name like com.android.mail for example.

what I'm trying to do is use this to get access to that application so I can display its icon to the user, but I cant find anything that lets me do this. Is there something that can help me?

I'm testing this app on my hero so the api level is 3 (android 1.5).

Thanks.

Upvotes: 9

Views: 14484

Answers (4)

Vinay
Vinay

Reputation: 1899

While packagemanager.getApplicationIcon(pkagename) works for some apps but not for all.

Found better answer here: how to get running applications icon on android programmatically

Uses:

Drawable ico=getApplicationInfo(packagemanager,PackageManager.GET_META_DATA).loadIcon(getPackageManager());

Upvotes: 0

Andrei Buneyeu
Andrei Buneyeu

Reputation: 6680

Since Android 3.0 you might want to get a bigger launcher icon that you can't get the way you described. If so, perhaps my answer to question below can help you: Getting App Icon in Android

Upvotes: 0

j2emanue
j2emanue

Reputation: 62519

try this way make a class called packageinformation:

public class 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 = no system packages */ final int max = apps.size(); for (int i=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; 
 }


 }

tuck this away somewhere and now to access the info from your working class do this:

  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;

}

Upvotes: 0

Joe
Joe

Reputation: 241

Ok, I figured out how to do it. In case your curious this is what I did.

private PackageManager pk;
pk = getPackageManager();
....
pk.getApplicationIcon(process.get(i).processName)

Thanks.

Upvotes: 15

Related Questions