總網頁瀏覽量

關於我自己

我的相片
人生的必修課是接受無常,人生的選修課是放下執著。

2012年2月24日 星期五

PackageInfo / ApplicationInfo / ResolveInfo 的比較



=======================List<PackageInfo>=======================================
PackageManager packageManager = context.getPackageManager();
List<PackageInfo> allappPagInfo = packageManager.getInstalledPackages(PackageManager.GET_ACTIVITIES);
System.out.println("100L pagInfo.size() : "+allappPagInfo.size());//48             
for(int i = 0 ; i <allappPagInfo.size() ; i ++)
{                 
    PackageInfo appPI = allappPagInfo.get(i);//PackageInfo{2ad3d2e0 com.android.launcher}
    String apPag = appPI.applicationInfo.packageName;//com.android.launcher
    String apName = appPI.applicationInfo.loadLabel(packageManager).toString();//Launcher
    Drawable apIcon = appPI.applicationInfo.loadIcon(packageManager);//android.graphics.drawable.BitmapDrawable@2ae37b08
    String dir = appPI.applicationInfo.publicSourceDir;
    long size = new File(dir).length();      //5015756
    ApplicationInfo allappInfo = appPI.applicationInfo;//ApplicationInfo{2ad14680 com.android.launcher}         
}


========================List<ApplicationInfo>==================================
PackageManager packageManager = context.getPackageManager();
List<ApplicationInfo> allappInfo = packageManager.getInstalledApplications(PackageManager.GET_ACTIVITIES);
System.out.println("100L allappInfo.size() : "+allappInfo.size());//48
for(int i = 0 ; i <allappInfo.size() ; i ++)
{
    ApplicationInfo appAI = allappInfo.get(i);
    String apPag = appAI.packageName;//com.android.launcher
    String apName = appAI.loadLabel(packageManager).toString();//Launcher
    Drawable apIcon = appAI.loadIcon(packageManager);        //android.graphics.drawable.BitmapDrawable@2ae99f60
    String dir = appAI.publicSourceDir;
    long size = new File(dir).length();      //5015756
    ApplicationInfo apInfo = appAI;        //ApplicationInfo{2ad52d98 com.android.launcher}
}

========================List<ResolveInfo>==================================
PackageManager packageManager = context.getPackageManager();
Intent intent=new Intent(Intent.ACTION_SEND,null);
intent.addCategory(Intent.CATEGORY_DEFAULT); 
intent.setType("text/plain"); 
List<ResolveInfo> allappInfo = packageManager.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);

for(int i = 0 ; i <allappInfo.size() ; i ++)
{
    ResolveInfo appRI = allappInfo.get(i);
    String apPag = appRI.activityInfo.packageName;
    String apName = appRI.loadLabel(packageManager).toString();
    Drawable apIcon = appRI.loadIcon(packageManager);
}

    -----------------------------------------以ArrayList<自訂類別>儲存搜尋結果    -----------------------------------------
    //先建立class
    public class AppInfo
    {
        public String apPag="";
        public String apName="";
        public Drawable apIcon=null;
    }  

        PackageManager packageManager = context.getPackageManager();
        List<ApplicationInfo> allappInfo = packageManager.getInstalledApplications(PackageManager.GET_ACTIVITIES);

        ArrayList<AppInfo> appInfo = new ArrayList<AppInfo>(); //用來存儲獲取的應用資訊資料
        for(int i=0;i<allappInfo.size();i++)
        {
            ApplicationInfo appAI = allappInfo.get(i);
            AppInfo tmpInfo = new AppInfo();
            tmpInfo.apPag = appAI.packageName;
            tmpInfo.apName = appAI.loadLabel(getPackageManager()).toString();
            tmpInfo.apIcon = appAI.loadIcon(getPackageManager());
            appInfo.add(tmpInfo);            
        }

    -----------------------------------------以ArrayList<String>儲存搜尋結果    -----------------------------------------
        PackageManager packageManager = context.getPackageManager();
        List<ApplicationInfo> allappInfo = packageManager.getInstalledApplications(PackageManager.GET_ACTIVITIES);

        ArrayList<ApplicationInfo> list_allappInfo = new ArrayList<ApplicationInfo>();
        ArrayList<String> list_apPag = new ArrayList<String>();
        ArrayList<String> list_apName = new ArrayList<String>();
        ArrayList<Drawable> list_apIcon = new ArrayList<Drawable>();            
        for(int i = 0 ; i <allappInfo.size() ; i ++)
        {
            ApplicationInfo appAI = allappInfo.get(i);
            list_allappInfo.add(appAI);
            String apPag = appAI.packageName;
            list_apPag.add(apPag);
            String apName = appAI.loadLabel(packageManager).toString();
            list_apName.add(apName);
            Drawable apIcon = appAI.loadIcon(packageManager);
            list_apIcon.add(apIcon);
        }

    -----------------------------------------以List<Map<String,Object>>儲存搜尋結果    -----------------------------------------
PackageManager packageManager = context.getPackageManager();
        List<ApplicationInfo> allappInfo = packageManager.getInstalledApplications(PackageManager.GET_ACTIVITIES);                
        ArrayList<Map<String,Object>> arrayMap = new ArrayList<Map<String,Object>>(allappInfo.size());
        for(int i = 0 ; i < allappInfo.size() ; i ++)
        {
            ApplicationInfo appAI = allappInfo.get(i);
            Map<String,Object> map=new HashMap<String,Object>();
            String apPag = appAI.packageName;     
            String apName = appAI.loadLabel(packageManager).toString();
            Drawable apIcon = appAI.loadIcon(packageManager);                    
            map.put("package", apPag);
            map.put("name", apName);
            map.put("icon",apIcon);
            //map : {icon=android.graphics.drawable.BitmapDrawable@2afbf9f0, name=VPN Services, package=com.android.server.vpn}
            arrayMap.add(map);
            //arrayMap : [{map}, {map}, {map}, ...]
        }

1 則留言: