Unable to access resources from APKs on the SD Card.
I am using the following snippet to get the application name a开发者_C百科nd icon of few of the APKs on my SD Card.
PackageInfo packageInfo = packageManager.getPackageArchiveInfo(apkPath, 0);
ApplicationInfo appInfo = packageInfo.applicationInfo;
Drawable appIcon = appInfo.loadIcon(packageManager);
String appName = appInfo.loadLabel(packageManager).toString();
I am able to access the package name but the loadIcon returns the default Android application icon for all the apks and the loadLabel returns the package name (Not the application label).
I also get the following warning messages in logcat:
Failure retrieving icon 0x7f020005 in package com.sample.radio
Failure retrieving text 0x7f050000 in package com.taskkiller.demo
I am running Android 2.2, any pointers will be appreciated. Thanks.
You may need to add two lines before creating appIcon, AppName:
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
// NEW LINES
pi.applicationInfo.sourceDir = APKFilePath;
pi.applicationInfo.publicSourceDir = APKFilePath;
String AppName = (String)pi.applicationInfo.loadLabel(pm);
Drawable appIcon=pm.getApplicationIcon(pi.applicationInfo);
精彩评论