Skip to content

Commit c628d01

Browse files
committed
Update ResourceUtil
1 parent 60ec040 commit c628d01

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

PluginCore/src/com/plugin/util/ResourceUtil.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
package com.plugin.util;
22

3+
import android.annotation.TargetApi;
34
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;
513
import com.plugin.core.PluginPublicXmlConst;
614

715
import java.lang.reflect.InvocationTargetException;
@@ -82,6 +90,46 @@ public static int getResourceId(String value) {
8290
return 0;
8391
}
8492

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+
85133
public static boolean isMainResId(int resid) {
86134
//如果使用的使openatlasextention
87135
//默认宿主的资源id以0x7f3X开头

0 commit comments

Comments
 (0)