80,348
社区成员
发帖
与我相关
我的任务
分享
private static String channel = null;
public static String getChannel(Context context) {
if (channel != null) {
return channel;
}
final String start_flag = "META-INF/channel_";
ApplicationInfo appinfo = context.getApplicationInfo();
String sourceDir = appinfo.sourceDir;
ZipFile zipfile = null;
try {
zipfile = new ZipFile(sourceDir);
Enumeration<?> entries = zipfile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
String entryName = entry.getName();
if (entryName.contains(start_flag)) {
channel = entryName.replace(start_flag, "");
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (zipfile != null) {
try {
zipfile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (channel == null || channel.length() <= 0) {
channel = "xiaoliangkou";//读不到渠道号就默认官方渠道
}
return channel;
}