zoukankan      html  css  js  c++  java
  • android 查看软件

    引用:http://www.eoeandroid.com/thread-21948-1-1.html


    程序代码部分:

    1. public class ApplicatonList extends Activity {
    2. private List<Map<String, Object>> data;
    3. Map<String, Object> item;
    4. private ListView listView = null;
    5. @Override
    6. public void onCreate(Bundle savedInstanceState) {
    7. super.onCreate(savedInstanceState);
    8. listView = new ListView(this);
    9. data = new ArrayList<Map<String, Object>>();
    10. listPackages();
    11. SimpleAdapter adapter = new SimpleAdapter(this, data,
    12. android.R.layout.simple_list_item_2, new String[] {"appname","pname" }, new int[] {
    13. android.R.id.text1, android.R.id.text2, });
    14. listView.setAdapter(adapter);
    15. setContentView(listView); 
    16. }
    17. class PInfo { 
    18. private String appname = ""; 
    19. private String pname = ""; 
    20. private String versionName = ""; 
    21. private int versionCode = 0; 
    22. private Drawable icon; 
    23. private void prettyPrint() { 
    24. Log.i("taskmanger",appname + "\t" + pname + "\t" + versionName + "\t" + versionCode + "\t"); 
    25. private void listPackages() { 
    26. ArrayList<PInfo> apps = getInstalledApps(false); /* false = no system packages */ 
    27. final int max = apps.size(); 
    28. for (int i=0; i<max; i++) { 
    29. apps.get(i).prettyPrint(); 
    30. item = new HashMap<String, Object>();
    31. item.put("appname", apps.get(i).appname);
    32. item.put("pname", apps.get(i).pname);
    33. data.add(item); 
    34. private ArrayList<PInfo> getInstalledApps(boolean getSysPackages) { 
    35. ArrayList<PInfo> res = new ArrayList<PInfo>(); 
    36. List<PackageInfo> packs = getPackageManager().getInstalledPackages(0); 
    37. for(int i=0;i<packs.size();i++) { 
    38. PackageInfo p = packs.get(i); 
    39. if ((!getSysPackages) && (p.versionName == null)) { 
    40. continue ; 
    41. PInfo newInfo = new PInfo(); 
    42. newInfo.appname = p.applicationInfo.loadLabel(getPackageManager()).toString(); 
    43. newInfo.pname = p.packageName; 
    44. newInfo.versionName = p.versionName; 
    45. newInfo.versionCode = p.versionCode; 
    46. newInfo.icon = p.applicationInfo.loadIcon(getPackageManager()); 
    47. res.add(newInfo); 
    48. return res; 
    49. }
    复制代码
  • 相关阅读:
    nginx Server names
    ES6--变量的声明及解构赋值
    Android ListView and Tips.
    Eclipse自己定义keystore
    POJ 1129 Channel Allocation(DFS)
    机器学习笔记十三:Ensemble思想(上)
    设计模式——享元模式具体解释
    老猪带你玩转自定义控件三——sai大神带我实现ios 8 时间滚轮控件
    老猪带你玩转android自定义控件二——自定义索引栏listview
    android动手写控件系列——老猪叫你写相机
  • 原文地址:https://www.cnblogs.com/sode/p/2566011.html
Copyright © 2011-2022 走看看