android軟體的資訊儲存在PackageInfo中,ApplicationInfo主要包括名字、Package標籤、版本資訊和表徵圖資訊,
源碼:
</p><p>import java.util.ArrayList;<br />import java.util.HashMap;<br />import java.util.List;<br />import java.util.Map;</p><p>import android.app.Activity;<br />import android.content.Context;<br />import android.content.pm.PackageInfo;<br />import android.content.pm.PackageManager;<br />import android.os.Bundle;<br />import android.view.LayoutInflater;<br />import android.view.View;<br />import android.view.ViewGroup;<br />import android.widget.BaseAdapter;<br />import android.widget.ImageView;<br />import android.widget.ListView;<br />import android.widget.TextView;<br />public class GestureStartActivity extends Activity {<br />private List<PackageInfo> packageInfos;</p><p>private ListView listView = null;</p><p>@Override</p><p>public void onCreate(Bundle savedInstanceState) {</p><p>super.onCreate(savedInstanceState);</p><p>listView = new ListView(this);</p><p>packageInfos = getPackageManager().getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.GET_ACTIVITIES);<br />ListViewAdapter adapter = new ListViewAdapter(GestureStartActivity.this, packageInfos);<br /> listView.setAdapter(adapter);</p><p> setContentView(listView); </p><p>}<br />class ListViewAdapter extends BaseAdapter {<br />LayoutInflater inflater;<br />List<PackageInfo> pkInfos;</p><p>public ListViewAdapter(Context context,List<PackageInfo> packageInfos) {<br />inflater = LayoutInflater.from(context);<br />this.pkInfos = packageInfos;<br />}</p><p>@Override<br />public int getCount() {<br />// TODO Auto-generated method stub<br />return pkInfos.size();<br />}</p><p>@Override<br />public Object getItem(int arg0) {<br />// TODO Auto-generated method stub<br />return pkInfos.get(arg0);<br />}</p><p>@Override<br />public long getItemId(int position) {<br />// TODO Auto-generated method stub<br />return position;<br />}</p><p>@Override<br />public View getView(int position, View convertView, ViewGroup parent) {<br />View view = inflater.inflate(R.layout.lv_item, null);<br />TextView tv_appname = (TextView) view.findViewById(R.id.lv_item_appname);<br />TextView tv_packagename = (TextView) view.findViewById(R.id.lv_item_packageame);<br />ImageView iv = (ImageView) view.findViewById(R.id.lv_icon);</p><p>//tv.setText(packageInfos.get(position).packageName);<br />tv_appname.setText(pkInfos.get(position).applicationInfo.loadLabel(getPackageManager()));<br />tv_packagename.setText(pkInfos.get(position).packageName);<br />iv.setImageDrawable(pkInfos.get(position).applicationInfo.loadIcon(getPackageManager()));<br />return view;<br />}<br />}</p><p>}