2011-07-07 21 views
0

在Eclipse中開發Android應用程序。Android - 在列表中列出應用程序圖標並運行選中

我有一個顯示安裝的應用程序列表,該列表是這樣的:

  //Listar apps instaladas 
     final ListView list1 = (ListView) findViewById(R.id.list1); 
     ArrayList results = new ArrayList(); 
     PackageManager pm = this.getPackageManager(); 
     Intent inte = new Intent(Intent.ACTION_MAIN, null); 
     inte.addCategory(Intent.CATEGORY_LAUNCHER); 
     List<ResolveInfo> list = pm.queryIntentActivities(inte, PackageManager.PERMISSION_GRANTED); 
     for (ResolveInfo rInfo : list) { 
      results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString()); 
     } 
      list1.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results)); 

我的問題是: 我怎樣才能做到那不是顯示的圖標的名稱?如果我去做了

results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString()); 

告訴我 「應用程序的android.graphics.drawable @名字」我該怎麼做才能運行通過單擊列表中的應用程序?我嘗試了幾次嘗試,但是發現應用程序錯誤。 謝謝!

回答

0

results.add(rInfo.activityInfo.applicationInfo.loadLabel(pm).toString()); 用這行代碼我假設你正在加載應用程序的標籤,所以也許你應該嘗試loadName或者什麼,檢查你可以選擇那裏,因爲我以前沒有做過這件事。

當你點擊列表時會得到哪個錯誤?這也會有所幫助:)

+0

嗨!我不知道訪問名稱,我的方法,我只得到標籤,圖標,desc,標誌和元數據... 當我點擊該項目,應用程序得到「應用程序已意外停止」 – Ghaelito

+1

此代碼: PackageManager pm = this.getPackageManager(); (i.hasNext()){ActivityManager.RunningAppProcessInfo info =(ActivityManager.RunningAppProcessInfo)(i.next());(i.hasNext() try { CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName,PackageManager.GET_META_DATA)); Log.w(「LABEL」,c.toString()); 將顯示活動的正在運行的應用程序名稱和一點點工作我相信您可以在屏幕上獲取所有應用程序名稱。 關於此錯誤,請檢查DDMS並向我們顯示,這對您和我們提供信息都很有幫助=) – kevin

相關問題