Tam*_*Tam 63
我花了更多的时间,而不是承认寻找解决方案......并找到了它!:) :)
徘徊到这个参考:http: //code.google.com/p/android/issues/detail?id = 9151 我发现了从.apk文件获取图标和名称(标签,即)的技巧没有安装.
我希望用这个帮助别人还为时不晚:
String APKFilePath = "mnt/sdcard/myapkfile.apk"; //For example...
PackageManager pm = getPackageManager();
PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
// the secret are these two lines....
pi.applicationInfo.sourceDir = APKFilePath;
pi.applicationInfo.publicSourceDir = APKFilePath;
//
Drawable APKicon = pi.applicationInfo.loadIcon(pm);
String AppName = (String)pi.applicationInfo.loadLabel(pm);
Run Code Online (Sandbox Code Playgroud)
经过轻度测试后,它似乎有效......哇.
小智 13
我试过了:
PackageInfo info = getPackageManager().getPackageArchiveInfo(fullPath, 0);
ApplicationInfo appinfo = info.applicationInfo;
label = getPackageManager().getApplicationLabel(appinfo).toString();
img = getPackageManager().getApplicationIcon(info.packageName);
Run Code Online (Sandbox Code Playgroud)
但如果没有安装apk,则无法使用此代码
我可以用得到的APK图标,版本,名称getPackageArchiveInfo(archiveFilePath, flags)和getApplicationIcon (ApplicationInfo info)
// Install a known apk file from the SD-Card
// or launch it if installed.
// -hsigmond
protected void runAppFromApkFileOnSdCard() {
final PackageManager pm = getActivity().getPackageManager();
String apkFileName = "application_name.apk";
String fullPath = "/sdcard/"+apkFileName;
PackageInfo packageInfo = pm.getPackageArchiveInfo(fullPath, 0);
Intent intent = pm.getLaunchIntentForPackage(packageInfo.packageName);
if( intent == null ){
File file = new File(fullPath);
intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setDataAndType(Uri.fromFile(file),
"application/vnd.android.package-archive");
}
startActivity(intent);
}
Run Code Online (Sandbox Code Playgroud)
使用:
packageInfo.applicationInfo.['name','icon','logo'] etc.
Run Code Online (Sandbox Code Playgroud)
示例图标:
Drawable icon = packageInfo.applicationInfo.loadIcon(getActivity().getPackageManager());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25351 次 |
| 最近记录: |