Android–擷取安裝的程式資訊

來源:互聯網
上載者:User

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>}

   



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.