GPK包解决方案

来源:互联网 发布:c语言加密程序2 编辑:程序博客网 时间:2024/05/10 01:21

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