String apkPath = apk.getAbsolutePath();
Log.i(getClass().getName(), "addApk(): apkPath = " + apkPath);
PackageInfo localPackageInfo = pm.getPackageArchiveInfo(apkPath, 0);
localPackageInfo.applicationInfo.sourceDir = apkPath;//! null point exception
can’t get apk’s icon, name, version etc. I also tried the magic number 8192 instead of 0, but does not work either.
Any one have any suggestion?
Thx in advance!
I changed my code to this:
PackageInfo pi = pm.getPackageArchiveInfo(apkPath, PackageManager.GET_ACTIVITIES);
if (pi != null) {
ApplicationInfo ai = pi.applicationInfo;
Drawable appIcon = pm.getApplicationIcon(ai);
String appName = pm.getApplicationLabel(ai).toString();
String appVersion = pi.versionName;
String pkgName = ai.packageName;
Log.i(getClass().getName(), "pkgName = " + pkgName + ", appName = " + appName + ", appVersion = " + appVersion);
adapter.add(new InstallItem(pkgName, appIcon, appName, appVersion));
}
and got output like this:
pkgName = com.chaozh.iReaderFree, appName = com.chaozh.iReaderFree, appVersion = 1.3.2.0 …
as you see here, i can’t get app name and its icon is always the default same icon.
I tired other installer in market and they works great, so any one tell me how to do? thx.
This this the correct answer, there are some tricks (SDK>8!):