下面給出的是我用來從手機中檢索應用程序列表的java和xml文件中的代碼。但是,它不會將應用程序的圖標與它一起檢索。任何人都可以提供解決方案,最好基於給定的代碼,我如何能夠實現檢索應用程序圖標的目標?幫助會非常讚賞如何檢索已安裝的應用程序中的圖標
XML文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView android:id="@+id/list1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
的java文件:
public class MainActivity extends Activity {
private ListView lView;
private ArrayList results;
List<ResolveInfo> list;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
results = new ArrayList();
lView = (ListView) findViewById(R.id.list1);
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_MAIN, null);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
list = pm.queryIntentActivities(intent,PackageManager.PERMISSION_GRANTED);
for (ResolveInfo rInfo : list)
{
results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
Log.w("Installed Applications", rInfo.activityInfo.applicationInfo.loadLabel(pm).toString());
}
lView.setAdapter(new ArrayAdapter(this,android.R.layout.simple_list_item_1, results));
}
你的意思是rInfo.getIconResource()返回0? – ben75