Android on Android phone to get the package name and version number of other apps

Source: Internet
Author: User

Tag: Code cat code Log Direct err map load ATI

There are many ways to get the package name and version number for other apps on your Android phone, which can be obtained directly from the APK package via AAPT or via code on your phone. Obviously, for the product or user to obtain this information, on the phone to obtain more convenient.

Let's look at how to get the package name, version number of the other app on the phone.

Core: Through Packagemanager can get the information we want, such as: program icon, program name, package name, Versionname, Versioncode and so on.

/** @Author Sun Ruichuan * **/         PublicArraylistGetItems (Context context) {Packagemanager Pckman=Context.getpackagemanager (); ArrayListNewArraylist(); List<PackageInfo> PackageInfo = Pckman.getinstalledpackages (0);  for(PackageInfo pinfo:packageinfo) {HashMap<string, object> item =NewHashmap<string, object>(); Item.put ("Appimage", PInfo.applicationInfo.loadIcon (Pckman)); Item.put ("PackageName", Pinfo.packagename); Item.put ("Versioncode", Pinfo.versioncode); Item.put ("Versionname", Pinfo.versionname); Item.put ("AppName", PInfo.applicationInfo.loadLabel (Pckman). toString ());        Items.Add (item); }        returnitems; }

Once you get the information you need, you can put that information into your custom Listadaptar.

classMyadapter extends Baseadapter { Public classHolder {TextView tv_pakagename;            TextView Tv_versioncode;            TextView Tv_versionname;            TextView Tv_appname;        ImageView Iv_logo; } @Override Public intGetCount () {returnallprocess.size (); } @Override PublicHashmap<string, Object> GetItem (intposition) {            returnAllprocess.Get(position); } @Override Public LongGetitemid (intposition) {            returnposition; } @Override PublicView GetView (intposition, View Convertview, ViewGroup parent)            {Holder Holder;            View v; if(Convertview = =NULL) {Holder=NewHolder (); V= Layoutinflater. from(Getapplicationcontext ()). Inflate (R.layout.list_menu,NULL); Holder.tv_pakagename=(TextView) v. Findviewbyid (r.id.tv_pakagename); Holder.tv_versioncode=(TextView) v. Findviewbyid (R.id.tv_versioncode); Holder.tv_versionname=(TextView) v. Findviewbyid (r.id.tv_versionname); Holder.iv_logo=(ImageView) V.findviewbyid (R.id.iv_logo); Holder.tv_appname=(TextView) V.findviewbyid (r.id.tv_appname);            V.settag (holder); } Else{v=Convertview; Holder=(Holder) V.gettag (); } holder.tv_pakagename.setText ("Package Name:"+ allprocess.Get(position).Get("PackageName"). toString ()); Holder.tv_versioncode.setText ("Versioncode:"+ allprocess.Get(position).Get("Versioncode"). toString ()); Holder.tv_versionname.setText ("Versionname:"+ allprocess.Get(position).Get("Versionname"). toString ()); Holder.iv_logo.setImageDrawable ((drawable) allprocess.Get(position).Get("Appimage")); Holder.tv_appname.setText ("App Name:"+ allprocess.Get(position).Get("AppName"). toString ()); returnv; }    }

This completes the corresponding work.

Android on Android phone to get the package name and version number of other apps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.