Android快速打渠道包
打包方法
因為Android在安裝apk時,不對META-INF文件夾的文件經行簽名校驗,
所以可以在這個文件夾隨添加/修改相關文件作為渠道標識
python ./package.py xxxxx.apk dev
最后一個參數是想要的渠道名稱
讀取渠道包
public static String getCustomChannelInfo(Context context){
if(!TextUtils.isEmpty(mChannel)){
return mChannel;
}
mChannel = "default";
ApplicationInfo appinfo = context.getApplicationInfo();
String sourceDir = appinfo.sourceDir;
Log.d("getChannel sourceDir", sourceDir);
ZipFile zf = null;
InputStream in = null;
ZipInputStream zin = null;
try {
zf = new ZipFile(sourceDir);
in = new BufferedInputStream(new FileInputStream(sourceDir));
zin = new ZipInputStream(in);
ZipEntry ze;
Enumeration<?> entries = zf.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = ((ZipEntry) entries.nextElement());
Log.d("getChannel getName", entry.getName());
if( entry.getName().equalsIgnoreCase("META-INF/channel_info")){
long size = entry.getSize();
if (size > 0) {
BufferedReader br = new BufferedReader( new InputStreamReader(zf.getInputStream(entry)));
String line;
while ((line = br.readLine()) != null) {
mChannel = line;
}
br.close();
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
finally {
if(in != null){
try {
in.close();
}
catch (Exception e){
}
}
if(zin != null){
try {
zin.closeEntry();
}
catch (Exception e){
}
}
if(zf != null){
try {
zin.closeEntry();
}
catch (Exception e){
}
}
}
Log.d("getChannel", mChannel);
return mChannel;
}</pre>https://github.com/seathink/Android-Package-Channel</code>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!