AggH5Tools.java
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package com.agg.h5game.tools;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class AggH5Tools {
// 获取Manifest.xml 中MetaData属性
public static String getMetaData(Context ctx, String key) {
try {
ApplicationInfo appInfo = ctx.getPackageManager()
.getApplicationInfo(ctx.getPackageName(),
PackageManager.GET_META_DATA);
if (appInfo != null && appInfo.metaData != null
&& appInfo.metaData.containsKey(key)) {
return "" + appInfo.metaData.get(key);
} else {
AggH5Log.e("TFSDK", "The meta-data key is not exists." + key);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String getLogicChannel(Context context, String prefix) {
ApplicationInfo appInfo = context.getApplicationInfo();
String sourceDir = appInfo.sourceDir;
String targetEntryName = findTargetEntryName(sourceDir, prefix);
if (!TextUtils.isEmpty(targetEntryName)) {
// 去掉 prefix_
String replaceStr = prefix + "_";
return targetEntryName.replace(replaceStr, "");
}
return "1";
}
private static String findTargetEntryName(String sourceDir, String prefix) {
String key = "META-INF/" + prefix;
try (ZipFile zip = new ZipFile(sourceDir)) {
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String entryName = entry.getName();
if (entryName.startsWith(key)) {
return entryName;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
}