public void parseapk (context context, String Apkfilepath) { Packagemanager Packagemanager = Context.getpackagemanager (); PackageInfo PackageInfo = Packagemanager.getpackagearchiveinfo (Apkfilepath, 0 ); if (PackageInfo! = null ) {packageInfo.applicationInfo.sourceDir = Apkfilepath; PackageInfo.applicationInfo.publicSourceDir = Apkfilepath; String name = PackageInfo.applicationInfo.loadLabel (Packagemanager). toString (); String PackageName = packageinfo.packagename; String versionname = packageinfo.versionname; int versioncode = Packageinfo.versioncode; drawable icondrawable = PackageInfo.applicationInfo.loadIcon (Packagemanager); }}
Note that you have to set ApplicationInfo SourceDir and Publicsourcedir after you get packageinfo, otherwise you will output the following error message and throw an exception when you read the label.
Failure retrieving text 0x7f050000 in package com.taskkiller.demo
When you read the icon, it will output the following error message and throw an exception.
Failure retrieving icon 0x7f020005 in package com.sample.radio
This is because both the label and the icon are in the resource, and the information inside the resource cannot be read without setting SourceDir and Publicsourcedir
android resolves the apk file on SD card