我正在尝试使用以下代码获取已安装应用程序图标的列表,但是它仅显示可绘制路径的列表,但不显示图标(即 android.graphics.drawable.BitmapDrawable@417530c8),
有人可以告诉我我做错了什么。
谢谢
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView appList = (ListView) findViewById(R.id.appList);
ArrayList<Drawable> cacheArrayList = new ArrayList<Drawable>();
ArrayAdapter<Drawable> aa = new ArrayAdapter<Drawable>(this,
android.R.layout.simple_list_item_1, cacheArrayList);
appList.setAdapter(aa);
PackageManager pm = getPackageManager();
List<ApplicationInfo> packages = pm
.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
// cacheArrayList.add((String) packageInfo.loadLabel(pm));
cacheArrayList.add(packageInfo.loadIcon(pm));
}
}
}