获得的设备上运行的应用程序图标 [英] getting Icons of applications running on device

查看:225
本文介绍了获得的设备上运行的应用程序图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表的活动显示该设备中的所有运行的应用程序。其显示为所有应用程序的默认图标。但我需要得到实际的应用程序图标列表中的每个应用程序。

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);
}

<一个href=\"http://stackoverflow.com/questions/2384713/how-to-get-the-icon-of-other-applications-android\">How获得其他应用程序的图标(Android版)
我试过这个链接,但我并没有把事情解决。所以任何一个可以帮助我。谢谢!

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!

推荐答案

试试这样

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

这篇关于获得的设备上运行的应用程序图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆