此工具根据网上一些资料进行编写
工具界面:
1.先设置自己的渠道文件channel.txt ,什么名字都行,只要是txt的
channel.txt的格式是:
渠道1
渠道2
渠道3
总之就是一个渠道之后换行。
之后选择你apk包存在的文件夹
之后再设置一下输出新包的目录,点击开始生成就行
之后生成的
Android代码里面获取渠道号的方法
ApplicationInfo appinfo = getApplicationInfo();
String sourceDir=appinfo.sourceDir;
getChannel(sorceDir);
public static String getChannel(String sourceDir) {
String ret = "";
java.util.zip.ZipFile zipfile = null;
try {
zipfile = new java.util.zip.ZipFile(sourceDir);
Enumeration<?> entries = zipfile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
String entryName = entry.getName();
if (entryName.startsWith("META-INF/channel")) {
ret = entryName;
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (zipfile != null) {
try {
zipfile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (!TextUtils.isEmpty(ret)) {
String[] split = ret.split("_");
if (split != null && split.length >= 2) {
return ret.substring(split[0].length() + 1);
} else {
return "";
}
} else {
return "";
}
}
工具下载地址:http://download.csdn.net/download/u014476720/10265267