Android多渠道分包解决方案:向META

阅读: 评论:0

Android多渠道分包解决方案:向META

Android多渠道分包解决方案:向META

文章目录

      • 一. 前言
      • 二. 在META-INF文件夹中塞入文件
          • 1. 塞入空文件
          • 2. 塞入非空文件


一. 前言

游戏要进行分渠道的推广,需要进行分包统计,如果挨个打包,或者执行批量重签名,如果渠道包很多,这个过程就会很耗时间,有一个办法就是在apk的META-INF文件夹中塞入渠道信息文件,运行的时候进行读取,不需要进行重签名,速度快。

二. 在META-INF文件夹中塞入文件

把.apk改成.zip,用解压工具进入zip内部,可以看到有个META-INF文件夹

往里面META-INF文件夹中塞入渠道信息文件,然后再把.zip改成.apk即可

1. 塞入空文件

塞入文件命名格式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;
}
2. 塞入非空文件

和上面的方法基本一样,只是文件为非空文件。
塞入的文件命名: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小时内删除。

标签:多渠道   解决方案   Android   META
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23