17

我需要使用新的 google-play(或市场)扩展库,但我很难使用它。我想知道是否有其他人在使用它并注意到我能看到的相同问题,所以如果您能帮助解决它们,我将非常高兴:

1.有时我不会将重要事件(例如错误)返回到下载器活动中。

2.它在某些设备上根本不起作用,比如 xoom 。我想我已经解决了: 在平板电脑上下载扩展文件

3.即使是相同的设备,一个可以下载文件,另一个总是会出现连接错误。对于某些设备,它永远无法下载(即使是具有 google-play 应用程序的非 root 设备)。

4.下载完成后,文件可能已损坏,所以我需要使用CRC检查并重新下载所有内容。

5.notification 有时会在按下它时打开下载器活动的多个实例。另外,我不明白他们为什么让通知停留在活动仍然显示的情况下。

6.当错误发生后处理时,不等用户告诉它恢复。我不确定它会在哪些情况下发生,但这真的很奇怪且不可预测。

7.在离开下载器活动时,我得到一个泄漏服务的异常。

8.应用程序混淆后,由于通过库完成的SQL操作而崩溃。这是怎么回事?为什么?编辑:这是因为 google 决定对 SQL 部分进行一些反射操作(在文件“DownloadsDB.java”中)。为了修复它,我尝试将 proguard 设置为忽略整个库(无论如何它是开源的),但它不起作用,所以我所做的就是自己提供它想要的类,所以我已经将“DownloadsDB.class.getDeclaredClasses()”替换为“new Class[] {MetadataColumns.class, DownloadColumns.class};” .

我只是不明白为什么谷歌不能发布一个简单的 API 来向市场发送一个下载文件并检查它是否正常的意图,或者提供一个不太复杂的库。由于复杂性,很难找到并修复他们的错误。

我的问题是:有没有其他人尝试过这个库,并且其他人成功地使用它没有任何问题?如果是这样,请发布解决方案...


编辑:似乎谷歌已经更新了它的库(到版本 2)。

他们声称接下来的变化:

  • 项目清单
  • 补丁文件现在被下载。
  • Honeycomb 设备现在支持类似 ICS 的通知
  • CRC 检查(来自示例)现在支持压缩的 Zip 文件
  • 移除反射的使用以允许容易混淆
  • 服务泄漏已修复
  • 从 ZipResourceFile 中删除的不可打印字符
  • 较小的格式更改
  • 对此文件的附加评论和编辑

我现在已经对其进行了测试,似乎它们几乎就在那里。

我发现的唯一错误是,如果我更新扩展文件(和 APK&filesize&CRC),下载会开始,但它不会删除旧的扩展文件。

此外,通知会显示当前时间,而不是其他可能与下载相关的时间。

现在,因为我只有一个扩展,所以每次从服务中获得 STATE_COMPLETED 状态时,我都会进行下一次检查。我希望它没有任何其他问题:

private void deleteOldExpansionFile()
{
  int fileVersion = 0;
  final int versionCode = App.getAppVersionCode(DownloaderActivity.this);
  fileVersion = versionCode;
  final String fileName = Helpers.getExpansionAPKFileName(this, true, fileVersion); //get the expansion file name based on the build version of the app.
  final File newFile = new File(Helpers.generateSaveFileName(this, fileName));
  final File[] listFiles = newFile.getParentFile().listFiles();
  for (final File file:listFiles)
  {
    final String name = file.getName();
    if (name.startsWith(fileName))
      continue;
    file.delete();
  }
}
4

2 回答 2

3

. 你好 !对于 CRC Check Fail,我也遇到过这个问题。为我解决它的事情是用 7zip 制作我的扩展文件的存档,以 zip 格式完全没有压缩(存储)。

像这样: http: //floy.fr/perso/floy/expfiles/crc.PNG

现在 CRC 对我来说就像一个魅力!

我同意你的看法..这个库使用起来很痛苦..

于 2012-04-18T11:31:49.987 回答
0

该代码不支持验证包含压缩文件的 Zip 文件。替换验证函数中的 doInBackground 循环,以使其正确验证 Zip 文件中的 CRC。请注意,您不能从 Zip 文件中压缩存储的文件流式传输视频/音频播放。

        @Override
        protected Boolean doInBackground(Object... params) {
            for (XAPKFile xf : xAPKS) {
                String fileName = Helpers.getExpansionAPKFileName(SampleDownloaderActivity.this,
                        xf.mIsMain, xf.mFileVersion);
                if (!Helpers.doesFileExist(SampleDownloaderActivity.this, fileName,
                        xf.mFileSize, false))
                    return false;
                fileName = Helpers
                        .generateSaveFileName(SampleDownloaderActivity.this, fileName);
                ZipResourceFile zrf;
                byte[] buf = new byte[1024 * 256];
                try {
                    zrf = new ZipResourceFile(fileName);
                    ZipEntryRO[] entries = zrf.getAllEntries();
                    /**
                     * First calculate the total compressed length
                     */
                    long totalCompressedLength = 0;
                    for (ZipEntryRO entry : entries) {
                        totalCompressedLength += entry.mCompressedLength;
                    }
                    float averageVerifySpeed = 0;
                    long totalBytesRemaining = totalCompressedLength;
                    long timeRemaining;
                    /**
                     * Then calculate a CRC for every file in the
                     * Zip file, comparing it to what is stored in
                     * the Zip directory. Note that for compressed
                     * Zip files we must extract the contents to do
                     * this comparison.
                     */
                    for (ZipEntryRO entry : entries) {
                        if (-1 != entry.mCRC32) {
                            long length = entry.mUncompressedLength;
                            CRC32 crc = new CRC32();
                            DataInputStream dis = null;
                            try {
                                dis = new DataInputStream(
                                        zrf.getInputStream(entry.mFileName));

                                long startTime = SystemClock.uptimeMillis();
                                while (length > 0) {
                                    int seek = (int) (length > buf.length ? buf.length
                                            : length);
                                    dis.readFully(buf, 0, seek);
                                    crc.update(buf, 0, seek);
                                    length -= seek;
                                    long currentTime = SystemClock.uptimeMillis();
                                    long timePassed = currentTime - startTime;
                                    if (timePassed > 0) {
                                        float currentSpeedSample = (float) seek
                                                / (float) timePassed;
                                        if (0 != averageVerifySpeed) {
                                            averageVerifySpeed = SMOOTHING_FACTOR
                                                    * currentSpeedSample
                                                    + (1 - SMOOTHING_FACTOR)
                                                    * averageVerifySpeed;
                                        } else {
                                            averageVerifySpeed = currentSpeedSample;
                                        }
                                        totalBytesRemaining -= seek;
                                        timeRemaining = (long) (totalBytesRemaining / averageVerifySpeed);
                                        this.publishProgress(
                                                new DownloadProgressInfo(
                                                        totalCompressedLength,
                                                        totalCompressedLength
                                                                - totalBytesRemaining,
                                                        timeRemaining,
                                                        averageVerifySpeed)
                                                );
                                    }
                                    startTime = currentTime;
                                    if (mCancelValidation)
                                        return true;
                                }
                                if (crc.getValue() != entry.mCRC32) {
                                    Log.e(Constants.TAG,
                                            "CRC does not match for entry: "
                                                    + entry.mFileName);
                                    Log.e(Constants.TAG,
                                            "In file: " + entry.getZipFileName());
                                    return false;
                                }
                            } finally {
                                if (null != dis) {
                                    dis.close();
                                }
                            }
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                }
            }
            return true;
        }
于 2012-05-01T05:00:08.163 回答