|
1 | 1 | package com.plugin.util;
|
2 | 2 |
|
| 3 | +import android.annotation.TargetApi; |
3 | 4 | import android.content.Context;
|
4 |
| - |
| 5 | +import android.content.pm.ApplicationInfo; |
| 6 | +import android.content.pm.PackageInfo; |
| 7 | +import android.content.pm.PackageManager; |
| 8 | +import android.graphics.drawable.Drawable; |
| 9 | +import android.os.Build; |
| 10 | + |
| 11 | +import com.plugin.content.PluginDescriptor; |
| 12 | +import com.plugin.core.PluginLoader; |
5 | 13 | import com.plugin.core.PluginPublicXmlConst;
|
6 | 14 |
|
7 | 15 | import java.lang.reflect.InvocationTargetException;
|
@@ -82,6 +90,46 @@ public static int getResourceId(String value) {
|
82 | 90 | return 0;
|
83 | 91 | }
|
84 | 92 |
|
| 93 | + public static String getLabel(PluginDescriptor pd) { |
| 94 | + PackageManager pm = PluginLoader.getApplication().getPackageManager(); |
| 95 | + PackageInfo info = pm.getPackageArchiveInfo(pd.getInstalledPath(), PackageManager.GET_ACTIVITIES); |
| 96 | + if (info != null) { |
| 97 | + ApplicationInfo appInfo = info.applicationInfo; |
| 98 | + appInfo.sourceDir = pd.getInstalledPath(); |
| 99 | + appInfo.publicSourceDir = pd.getInstalledPath(); |
| 100 | + String label = pm.getApplicationLabel(appInfo).toString(); |
| 101 | + if (label != null && label.equals(pd.getPackageName())) { |
| 102 | + //可能设置的lable是来自宿主的资源 |
| 103 | + if (pd.getDescription() != null) { |
| 104 | + int id = ResourceUtil.getResourceId(pd.getDescription()); |
| 105 | + if (id != 0) { |
| 106 | + //再宿主中查一次 |
| 107 | + try { |
| 108 | + label = PluginLoader.getApplication().getResources().getString(id); |
| 109 | + } catch (Exception e) { |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + return label; |
| 115 | + } |
| 116 | + return pd.getDescription(); |
| 117 | + } |
| 118 | + |
| 119 | + @TargetApi(Build.VERSION_CODES.GINGERBREAD) |
| 120 | + public static Drawable getLogo(PluginDescriptor pd) { |
| 121 | + PackageManager pm = PluginLoader.getApplication().getPackageManager(); |
| 122 | + PackageInfo info = pm.getPackageArchiveInfo(pd.getInstalledPath(), PackageManager.GET_ACTIVITIES); |
| 123 | + if (info != null) { |
| 124 | + ApplicationInfo appInfo = info.applicationInfo; |
| 125 | + appInfo.sourceDir = pd.getInstalledPath(); |
| 126 | + appInfo.publicSourceDir = pd.getInstalledPath(); |
| 127 | + Drawable logo = pm.getApplicationLogo(appInfo); |
| 128 | + return logo; |
| 129 | + } |
| 130 | + return null; |
| 131 | + } |
| 132 | + |
85 | 133 | public static boolean isMainResId(int resid) {
|
86 | 134 | //如果使用的使openatlasextention
|
87 | 135 | //默认宿主的资源id以0x7f3X开头
|
|
0 commit comments