基于aapt实现全尺寸解析apk图标

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;imp
摘要由CSDN通过智能技术生成
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") - 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值