如果意外删除Android应用程序的OBB文件,如何重新下载?

时间:2016-12-28 06:00:14

标签: java android

我正在开发一个Android应用程序,它使用OBB文件作为存储媒体文件的数据库。假设,如果用户错误地从手机中删除OBB文件,我将无法再次下载。如何通过Google Playstore重定向OBB文件下载,就像在Asphalt移动应用程序中一样?

1 个答案:

答案 0 :(得分:0)

应用程序中的主要活动(由启动器图标启动的活动)负责验证扩展文件是否已在设备上,如果不是,则启动下载。

使用下载程序库开始下载需要执行以下步骤:

1.检查文件是否已下载。

boolean expansionFilesDelivered() {
for (XAPKFile xf : xAPKS) {
        String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsBase,
        xf.mFileVersion);
        if (!Helpers.doesFileExist(this, fileName, xf.mFileSize, false))
            return false;
    }
    return true;
}

2.通过调用静态方法启动下载。

DownloaderClientMarshaller.startDownloadServiceIfRequired(Context c, PendingIntent notificationClient, Class<?> serviceClass)

3.当startDownloadServiceIfRequired()方法返回NO_DOWNLOAD_REQUIRED以外的任何内容时,通过调用

创建一个IStub实例
DownloaderClientMarshaller.CreateStub(IDownloaderClient client, Class<?> downloaderService). 

您可以按照此处的详细实施步骤操作。 https://developer.android.com/google/play/expansion-files.html#Download