package com.xunlei.app.tools;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* @author pengjin 2013-08-01
*
*
* apk icon全尺寸解析(解决有些apk解析信息比较特殊的bug:application-icon-120:'res/drawable-xlarge-mdpi/appicon.xml)
*/
public class ApkIconTool {
public static String separator = File.separator;
static String[] dpis = new String[] { "ldpi", "mdpi", "hdpi", "xhdpi" };
/**
* 解析获取icon
*
* @param apkPath
* @param imgPath
* @throws InterruptedException
* @throws IOException
*/
public static void getIcon(String apkPath, String imgPath)
throws InterruptedException, IOException {
// 通过aapt解析apk信息到文件中
String apkName = apkPath.substring(apkPath.lastIndexOf(separator) + 1);
if (!isLinux() && apkName.indexOf(".") != -1) {
apkName = apkName.substring(0, apkName.lastIndexOf("."));
}
String imgDir = imgPath
.substring(0, imgPath.lastIndexOf(separator) + 1);
String imgName = imgPath.substring(imgPath
.lastIndexOf(separator) + 1);
String aaptPath = ApkIconTool.class.getClassLoader()
.getResource("config.xml").getPath();
// 打包后在windows环境下
if (aaptPath.startsWith("file:/") && !isLinux()) {
//System.out.println("run in windows");
aaptPath = aaptPath.substring(6);
}
// 打包后在linux环境下
if (aaptPath.startsWith("file:/") && isLinux()) {
//System.out.println("run in linux");
aaptPath = aaptPath.substring(5);
}
// 调试环境和linux下aaptPath都会以"/"开头
if (aaptPath.startsWith("/") && !isLinux()) {
//System.out.println("调试环境下");
aaptPath = aaptPath.substring(1);
}
aaptPath = aaptPath.substring(0, aaptPath.indexOf("config.xml") -
基于aapt实现全尺寸解析apk图标
最新推荐文章于 2022-07-11 07:35:00 发布
本文介绍如何通过aapt工具深入解析apk文件,详细步骤解析apk中的图标资源,获取全尺寸的未压缩图像,适用于Android应用开发者进行资源分析和图标提取。
摘要由CSDN通过智能技术生成