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