public static String getLabel(PluginDescriptor pd) { PackageManager pm = PluginLoader.getApplication().getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(pd.getInstalledPath(), PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; appInfo.sourceDir = pd.getInstalledPath(); appInfo.publicSourceDir = pd.getInstalledPath(); String label = null; try { if (!isMainResId(appInfo.labelRes)) { label = pm.getApplicationLabel(appInfo).toString(); } } catch (Resources.NotFoundException e) { } if (label == null || label.equals(pd.getPackageName())) { // 可能设置的lable是来自宿主的资源 if (pd.getDescription() != null) { int id = ResourceUtil.getResourceId(pd.getDescription()); if (id != 0) { // 再宿主中查一次 try { label = PluginLoader.getApplication().getResources().getString(id); } catch (Resources.NotFoundException e) { } } } } if (label != null) { return label; } } return pd.getDescription(); }
public static Bundle getApplicationMetaData(String apkPath) { // 暂时只查询Applicatoin节点下的meta信息,其他组件节点下的meta先不管 PackageInfo info = PluginLoader.getApplication() .getPackageManager() .getPackageArchiveInfo(apkPath, PackageManager.GET_META_DATA); if (info.applicationInfo != null) { return info.applicationInfo.metaData; } return null; }
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public static Drawable getLogo(PluginDescriptor pd) { PackageManager pm = PluginLoader.getApplication().getPackageManager(); PackageInfo info = pm.getPackageArchiveInfo(pd.getInstalledPath(), PackageManager.GET_ACTIVITIES); if (info != null) { ApplicationInfo appInfo = info.applicationInfo; appInfo.sourceDir = pd.getInstalledPath(); appInfo.publicSourceDir = pd.getInstalledPath(); Drawable logo = pm.getApplicationLogo(appInfo); return logo; } return null; }