0

In my project I am able to upload the 470mb of my expansion file and it is getting download while I download my apk. If my expansion file is not found how should I direct my app to download the expansion file from play store? I tried following the instructions given in the following link enter link description here

1 Answers1

0

Please follow sample code available for expansion file download along with apk. Your first activity of application must be expansion file downloader activity in which there must be one method which will check expansion file has already downloaded or not.

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;
    }

If this method returns false you need to download expansion file.So you need to write download code for expansion file in else part like below.

    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();
                }

In above code ExpansionDownloader is main class which will handle downloading process.You can get ExpansionService and ExpansionReceiver classes from sample code.

Jay Shah
  • 732
  • 4
  • 16