1. Obtain installation package information
Copy the codeThe code is as follows:
/**
* Get information about the apk package: version number, name, icon, etc.
* @param absPath AbsPath AbsK package absolute path
* @param context
*/
public void apkInfo(String absPath,Context context) {
PackageManager pm = ();
PackageInfo pkgInfo = (absPath,PackageManager.GET_ACTIVITIES);
if (pkgInfo != null) {
ApplicationInfo appInfo = ;
/* These two sentences must be added, otherwise the icon below is the default icon instead of the application package */
= absPath;
= absPath;
String appName = (appInfo).toString();// Get the application name
String packageName = ; // Get the package name
String version = ; // Get version information
/* icon1 and icon2 are actually the same */
Drawable icon1 = (appInfo);// Get icon information
Drawable icon2 = (pm);
String pkgInfoStr = ("PackageName:%s, Vesion: %s, AppName: %s", packageName, version, appName);
(TAG, ("PkgInfo: %s", pkgInfoStr));
}
}
* Get information about the apk package: version number, name, icon, etc.
* @param absPath AbsPath AbsK package absolute path
* @param context
*/
public void apkInfo(String absPath,Context context) {
PackageManager pm = ();
PackageInfo pkgInfo = (absPath,PackageManager.GET_ACTIVITIES);
if (pkgInfo != null) {
ApplicationInfo appInfo = ;
/* These two sentences must be added, otherwise the icon below is the default icon instead of the application package */
= absPath;
= absPath;
String appName = (appInfo).toString();// Get the application name
String packageName = ; // Get the package name
String version = ; // Get version information
/* icon1 and icon2 are actually the same */
Drawable icon1 = (appInfo);// Get icon information
Drawable icon2 = (pm);
String pkgInfoStr = ("PackageName:%s, Vesion: %s, AppName: %s", packageName, version, appName);
(TAG, ("PkgInfo: %s", pkgInfoStr));
}
}
2. When installing APK, we can obtain information such as installation package, version, package name, etc.
Copy the codeThe code is as follows:
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
(savedInstanceState);
setContentView();
String archiveFilePath="sdcard/";//Installation package path
PackageManager pm = getPackageManager();
PackageInfo info = (archiveFilePath, PackageManager.GET_ACTIVITIES);
if(info != null){
ApplicationInfo appInfo = ;
String appName = (appInfo).toString();
String packageName = ; //Get the installation package name
String version=; //Get version information
// (, , Toast.LENGTH_LONG).show();
Drawable icon = (appInfo);//Get icon information
TextView tv = (TextView)findViewById();
("appName:"+appName+"---packageName:"+packageName);
//Show icon
ImageView tu=(ImageView)findViewById(.imageView1);
(icon);
}
}
}
}
}