GPK包解决方案

1、下载GPK包在电脑解压后把数据包文件夹复制到Android - obb文件夹下,然后安装apk文件。

2、问题:把GPK包复制到手机上改后缀名为 .zip ,然后解压后发现数据包不存在,测试手机HTC-ONE

3、把GPK包复制到手机SD卡,然后改后缀名为.zip,然后解压后发现数据包不是以文件夹形式存在,但是复制到电脑上是文件夹,很奇怪,这时候必须重新建立一个文件夹(文件夹名字为com.xx.xx),然后把数据包改名字(把/前面的连同/去掉)然后点击apk文件安装成功。测试手机(mx2

4、把GPK包复制到手机SD卡,然后改后缀名为.zip,发现没有解压缩的应用软件。测试手机三星9100


注:以上机型采用电脑端解压缩后把数据包复制到Android - obb文件夹下,然后安装apk文件均成功。


/**
	 * 解压只有一个文件组成的zip到当前目录,并且给解压出的文件重命名
	 * 
	 * @param zipPath
	 *            :文件绝对路径
	 * @param name
	 *            :新名字
	 * @throws IOException
	 */
	@SuppressLint("NewApi")
	public static void unzipSingleFileHereWithFileName(String zipPath,
			String name) throws IOException {
		boolean isNullPath = stringIsNull(zipPath);
		boolean isNullName = stringIsNull(name);
		if (isNullPath == true && isNullName == true) {
			File zipFile = new File(zipPath);

			if (zipFile.exists()) {
				File unzipFile = new File(zipFile.getParent() + "/" + name);
				ZipInputStream zipInStream = null;
				FileOutputStream unzipOutStream = null;
				try {
					zipInStream = new ZipInputStream(new FileInputStream(
							zipFile));
					ZipEntry zipEntry = zipInStream.getNextEntry();
					if (!zipEntry.isDirectory()) {
						unzipOutStream = new FileOutputStream(unzipFile);
						byte[] buf = new byte[4096];
						int len = -1;
						while ((len = zipInStream.read(buf)) != -1) {
							unzipOutStream.write(buf, 0, len);

						}
					}
				} finally {
					if (unzipOutStream != null) {
						unzipOutStream.close();
					}

					if (zipInStream != null) {
						zipInStream.close();
					}
				}
			} else {
				LogUtil.logE(name + " no exist");
			}
		} else {
			LogUtil.logE(" zipPath or name  is null");
		}
	}

注:只能解压一个文件或图片压缩的包


/**
	 * 
	 * @param zipFile
	 *            :源zip文件的完整路径
	 * @param targetDir
	 *            :解压缩后存放的文件夹
	 */
	public static void Unzip(String zipFile, String targetDir) {
		int BUFFER = 10 * 1024 * 1024; // 这里缓冲区我们使用4KB,
		String strEntry; // 保存每个zip的条目名称
		boolean isNullPath = stringIsNull(zipFile);
		boolean isNullName = stringIsNull(targetDir);
		File entryFile = null;
		if (isNullPath == true && isNullName == true) {
			try {
				BufferedOutputStream dest = null; // 缓冲输出流
				FileInputStream fis = new FileInputStream(zipFile);
				ZipInputStream zis = new ZipInputStream(
						new BufferedInputStream(fis));
				ZipEntry entry; // 每个zip条目的实例

				while ((entry = zis.getNextEntry()) != null) {

					try {
						Log.i("Unzip: ", "=" + entry);
						int count;
						byte data[] = new byte[BUFFER];
						strEntry = entry.getName();
						LogUtil.logE(strEntry);
						if (strEntry.contains("\\")) {
							String newStrEntry = strEntry.replace("\\", "/");
							entryFile = new File(targetDir + newStrEntry);
						} else {
							entryFile = new File(targetDir + strEntry);
						}

						File entryDir = new File(entryFile.getParent());
						if (!entryDir.exists()) {
							entryDir.mkdirs();
						} else {
							Log.i("Unzip: ", "not exists");
						}
						FileOutputStream fos = new FileOutputStream(entryFile);
						dest = new BufferedOutputStream(fos, BUFFER);
						while ((count = zis.read(data, 0, BUFFER)) != -1) {
							dest.write(data, 0, count);
						}
						dest.flush();
						dest.close();
					} catch (Exception ex) {
						ex.printStackTrace();
					}
				}
				zis.close();
			} catch (Exception cwj) {
				cwj.printStackTrace();
			}
		} else {
			LogUtil.logE(" zipPath or name  is null");
		}
	}

注:解压多个文件以及有文件夹的压缩包:mx2测试成功,HTC ONE  测试10分钟都不能完成解压,而mx2只需要7秒钟就解压完毕。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值