How to obtain APK installation package information in Android _android

Source: Internet
Author: User

First, get installation package information

Copy Code code as follows:
/**
* Get APK Package Information: Version number, name, icon, etc.
* @param the absolute path of the Abspath APK package
* @param context
*/
public void Apkinfo (String abspath,context context) {

Packagemanager pm = Context.getpackagemanager ();
PackageInfo pkgInfo = Pm.getpackagearchiveinfo (abspath,packagemanager.get_activities);
if (pkgInfo!= null) {
ApplicationInfo appInfo = Pkginfo.applicationinfo;
/* Must add these two sentences, or the following icon to get the default icon instead of the application package icon * *
Appinfo.sourcedir = Abspath;
Appinfo.publicsourcedir = Abspath;
String appName = Pm.getapplicationlabel (appInfo). toString ();//Get Application Name
String PackageName = appinfo.packagename; Get the package name
String Version = Pkginfo.versionname; Get version Information
* Icon1 and Icon2 are actually the same * *
drawable Icon1 = Pm.getapplicationicon (appInfo)//Get icon information
drawable icon2 = Appinfo.loadicon (PM);
String pkginfostr = String.Format ("packagename:%s, Vesion:%s, AppName:%s", PackageName, version, AppName);
LOG.I (TAG, String.Format ("PkgInfo:%s", pkginfostr));
}
}

Second, in the APK installation, we can obtain installation package, version, package name and other information.

Copy Code code as follows:

public class Testactivity extends activity {
@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
String archivefilepath= "sdcard/jb51.net.apk";//install package path
Packagemanager pm = Getpackagemanager ();
PackageInfo info = pm.getpackagearchiveinfo (Archivefilepath, packagemanager.get_activities);
if (info!= null) {
ApplicationInfo appInfo = Info.applicationinfo;
String appName = Pm.getapplicationlabel (appInfo). toString ();
String PackageName = appinfo.packagename; Get installation package Name
String Version=info.versionname; Get version Information
Toast.maketext (Testactivity.this, Toast.length_long). Show ();
drawable icon = Pm.getapplicationicon (appInfo);//Get icons Information
TextView TV = (TextView) Findviewbyid (r.id.tv);
Tv.settext ("AppName:" +appname+ "---packagename:" +packagename);
Display icon
ImageView tu= (ImageView) Findviewbyid (R.ID.IMAGEVIEW1);
Tu.setbackgrounddrawable (icon);
}
}

}
}

}

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.