簡體   English   中英

如果找不到擴展文件,如何從我的代碼中調用擴展文件?

[英]How to call the expansion file from my code if the expansion file is not found?

在我的項目中,我能夠上傳470mb的擴展文件,而在我下載apk時,它正在下載。 如果找不到我的擴展文件,我應該如何指導我的應用從Play商店下載擴展文件? 我嘗試按照以下鏈接中給出的說明在此處輸入鏈接描述

請遵循可用於擴展文件下載的示例代碼以及apk。 應用程序的第一個活動必須是擴展文件下載器活動,其中必須有一種方法可以檢查擴展文件是否已下載。

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

如果此方法返回false,則需要下載擴展文件。因此,您需要在其他部分編寫擴展文件的下載代碼,如下所示。

    initializeDownloadUI();
    Intent launchIntent = ExpansionDownloader.this.getIntent();
                    Intent intentToLaunchThisActivityFromNotification = new Intent(
                            ExpansionDownloader.this,
                            ExpansionDownloader.this.getClass());
                    intentToLaunchThisActivityFromNotification
                            .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                    | Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    intentToLaunchThisActivityFromNotification
                            .setAction(launchIntent.getAction());

                    if (launchIntent.getCategories() != null) {
                        for (String category : launchIntent.getCategories()) {
                            intentToLaunchThisActivityFromNotification
                                    .addCategory(category);
                        }
                    }

                    // Build PendingIntent used to open this activity from
                    // Notification
                    PendingIntent pendingIntent = PendingIntent.getActivity(
                            ExpansionDownloader.this, 0,
                            intentToLaunchThisActivityFromNotification,
                            PendingIntent.FLAG_UPDATE_CURRENT);
                    // Request to start the download
                    int startResult = DownloaderClientMarshaller
                            .startDownloadServiceIfRequired(this, pendingIntent,
                                    ExpansionService.class);

                    if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
                        // The DownloaderService has started downloading the files,
                        // show progress
                        initializeDownloadUI();
                        return;
                    } // otherwise, download not needed so we fall through to
                        // starting the movie
                } catch (NameNotFoundException e) {
                    Log.e(LOG_TAG, "Cannot find own package! MAYDAY!");
                    e.printStackTrace();
                }

在上面的代碼中,ExpansionDownloader是處理下載過程的主類。您可以從示例代碼中獲取ExpansionService和ExpansionReceiver類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM