2011-05-07 122 views
-1

問候!我想要獲得Android中已建立的附錄列表。但是列表僅在LogCat中顯示。如何寫,它顯示在手機上? 我用給定的代碼: 的java:我如何獲得所有安裝的應用程序列表?

package com.tipfile;  
import java.util.ArrayList; 
import android.app.Activity; 
import android.os.Bundle; 
import android.content.Intent; 
import android.content.pm.PackageManager; 
import android.content.pm.ResolveInfo; 

public class dop extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    PackageManager pm = this.getPackageManager(); 

    Intent intent = new Intent(Intent.ACTION_MAIN, null); 
    intent.addCategory(Intent.CATEGORY_LAUNCHER); 

    ArrayList<ResolveInfo> list = (ArrayList<ResolveInfo>) 
    pm.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED); 
    for (ResolveInfo rInfo : list) { 
    System.out.println("Installed Applications " + rInfo.activityInfo.applicationInfo.loadLabel(pm).toString()); 
    }}} 

XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<TextView 
    android:id="@+id/textSelest" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textStyle="bold"/> 
<ListView 
    android:id="@android:id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:drawSelectorOnTop="false"/> 
</LinearLayout> 

譯者通過網上寫道。我不懂英語。

回答

相關問題