Skip to content

Instantly share code, notes, and snippets.

@nukc
Last active February 8, 2017 09:48
Show Gist options
  • Save nukc/f777b54232be56f04171bcef56a627e1 to your computer and use it in GitHub Desktop.
Save nukc/f777b54232be56f04171bcef56a627e1 to your computer and use it in GitHub Desktop.
获取 META-INF 目录下的空渠道文件名
package io.virtualapp.utils;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import java.io.IOException;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class ChannelHelper {
public static String getChannel(Context context) {
ApplicationInfo appinfo = context.getApplicationInfo();
String sourceDir = appinfo.sourceDir;
String ret = "";
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.startsWith("META-INF/c_")) {
ret = entryName;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (zipfile != null) {
try {
zipfile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
String[] split = ret.split("_");
if (split != null && split.length >= 2) {
return ret.substring(split[0].length() + 1);
} else {
return "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment