游戏要进行分渠道的推广,需要进行分包统计,如果挨个打包,或者执行批量重签名,如果渠道包很多,这个过程就会很耗时间,有一个办法就是在apk的META-INF文件夹中塞入渠道信息文件,运行的时候进行读取,不需要进行重签名,速度快。
把.apk改成.zip,用解压工具进入zip内部,可以看到有个META-INF文件夹
往里面META-INF文件夹中塞入渠道信息文件,然后再把.zip改成.apk即可
塞入文件命名格式channel_xxx,不需要后缀名,例channel_5343
读取渠道信息的java代码如下
public static String GetChannelMsg()
{String channelMsg = "";final String start_flag = "META-INF/channel_";ApplicationInfo app_info = ApplicationInfo();String courceDir = app_info.sourceDir;ZipFile zipFile = null;try {zipFile = new ZipFile(courceDir);Enumeration<?> entries = ies();while(entries.hasMoreElements()){ZipEntry entry = ((Element());String entryName = Name();if(entryName.startsWith(start_flag)){channelMsg = place(start_flag, "");break;}}} catch (IOException e) {// TODO: handle exceptione.printStackTrace();}finally{if(zipFile != null){try {zipFile.close();} catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}}}if(null == channelMsg || channelMsg.length() <= 0){channelMsg = "";}return channelMsg;
}
和上面的方法基本一样,只是文件为非空文件。
塞入的文件命名:channel.properties
内容比如:
{"channel","5343"}
读取渠道信息文件的代码如下
import java.io.BufferedReader;public static String GetChannelMsg()
{String channelMsg = "";final String start_flag = "META-INF/channel.properties";ApplicationInfo app_info = ApplicationInfo();String courceDir = app_info.sourceDir;ZipFile zipFile = null;try {zipFile = new ZipFile(courceDir);Enumeration<?> entries = ies();while(entries.hasMoreElements()){ZipEntry entry = ((Element());String entryName = Name();if(entryName.startsWith(start_flag)){// 读取文件内容long size = Size();if(size > 0){BufferedReader br = new BufferedReader(new InputStream(entry)));String line;while((line = br.readLine()) != null){channelMsg += line;}}break;}}} catch (IOException e) {// TODO: handle exceptione.printStackTrace();}finally{if(zipFile != null){try {zipFile.close();} catch (IOException e2) {// TODO: handle exceptione2.printStackTrace();}}}if(null == channelMsg || channelMsg.length() <= 0){channelMsg = "";}return channelMsg;
}
本文发布于:2024-02-02 15:43:24,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170685980244788.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |