2

I've looked at quite some many sources that try to explain how to download / extract / use expansion files in Android such as a) this stackoverflow question or b) this official documentation, but I'm still struggling with getting my app to download the expansion files.

Does someone have a minimum working example, how I can download and expansion file from inside my existing app?

Regarding the two sources given above:
a) I copied all the helper libraries to my project as described, but I would still need a minimum toy example how to download the expansion files now.
b) In section Starting the download point 3 it gives an example how to modify my onCreate method to start the download. However I'm not sure how to adapt it:

@Override
public void onCreate(Bundle savedInstanceState) {
    // Check if expansion files are available before going any further
    if (!expansionFilesDelivered()) {
    // Build an Intent to start this activity from the Notification
    Intent notifierIntent = new Intent(this, MainActivity.getClass());
    notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                            Intent.FLAG_ACTIVITY_CLEAR_TOP);
    ...
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notifierIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Start the download service (if required)
    int startResult =
        DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
                    pendingIntent, SampleDownloaderService.class);
    // If download has started, initialize this activity to show
    // download progress
    if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
        // This is where you do set up to display the download progress
        //...
        // Instantiate a member instance of IStub
        mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this,
                SampleDownloaderService.class);
        // Inflate layout that shows download progress
        setContentView(R.layout.downloader_ui);
        return;
    } // If the download wasn't necessary, fall through to start the app
    }
    startApp(); // Expansion files are available, start the app
}

I'm not sure about the interface downloader_ui that should show the downloading progress. What should be the content of downloader_ui? Is this an activity that pops up ontop of my app and closes after finishing the download?
The startApp() is also meaningless in my case, since I'm already in the onCreate method of my app. Rather I would need my app to wait until the download is finished and then continue with the rest of the onCreate method...

Sorry for editing my question that much, but the problem is evolving ;)

Community
  • 1
  • 1
mcExchange
  • 6,154
  • 12
  • 57
  • 103
  • 1
    Possible duplicate of [How to make Android Expansion File using Android Studio?](http://stackoverflow.com/questions/22368251/how-to-make-android-expansion-file-using-android-studio) – Code-Apprentice Aug 29 '16 at 18:09
  • Why do you say [this link](https://developer.android.com/google/play/expansion-files.html) is out of date and only for Eclipse? I don't see anything on that page that is specific to Eclipse. – Code-Apprentice Aug 29 '16 at 18:11
  • No I looked into that post as well. If you look in the comments of that answer you will see that the answer is marked as outdated. "So with the new SDK update apache has been removed making this approach bad since AndroidHTTPClient is included in the src files" - Warpzit – mcExchange Aug 29 '16 at 18:13
  • Also, the `android update project` command is **very** outdated. Instead, you need to find the correct dependencies lines to add to your `build.gradle` file. – Code-Apprentice Aug 29 '16 at 18:14
  • Well the `android update project` command was mentioned in the official documentation, I'm not sure whether its specific for Eclipse or not (read it somewhere), but it's at least not working for me and Android studio – mcExchange Aug 29 '16 at 18:17
  • `android update project` is based on the old Ant build which could be used from the command-line or Eclipse. – Code-Apprentice Aug 29 '16 at 18:58
  • Yes I tried to use it from the command line but I'm getting the following error `Error: ... MyAppParentFolder is not a valid project (AndroidManifest.xml not found`). Maybe I'm pointing it to the wrong directory? – mcExchange Aug 29 '16 at 19:05
  • I assume you are using Gradle. The `android update project` command only works with Ant, not Gradle. Instead, you need to either find a dependency to add to `dependencies` in `build.gradle`. Or you need to download the source code as described in the linked documentation and import it as a module into Android Studio. – Code-Apprentice Aug 29 '16 at 19:09
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/122138/discussion-between-mcexchange-and-code-apprentice). – mcExchange Aug 29 '16 at 19:21
  • Unfortunately I'm still struggling with downloading an Expansion File from within my application? Can someone please provide with some minimal example? – mcExchange Sep 25 '16 at 13:21
  • After looking more closely at, [APK Expansion Files](https://developer.android.com/google/play/expansion-files.html#Overview) I think it has instructions for Android Studio. Under the heading "Preparing to use the Downloader Library" starting with "Create a new library module for the License Verification Library and Downloader Library...". What happens when you follow those instructions? – Code-Apprentice Sep 25 '16 at 17:47
  • Also, why is [this question](http://stackoverflow.com/q/22368251/1440565) not detailed enough for you. Which part do you get stuck on? – Code-Apprentice Sep 25 '16 at 17:51
  • I did all of that. Now I need to handle the downloading from inside my existing app. The official documentation gives some sample code to download the file, but I'm not sure how to adapt it. It says for example `startApp(); // Expansion files are available, start the app` and ` // Inflate layout that shows download progress setContentView(R.layout.downloader_ui);`. I pasted all code inside my `MainActivity.java` so there I can't call `startApp` because I'm already in the `onCreate` method of my app. I'm not sure how `downloader_ui.xml` should look like... – mcExchange Sep 27 '16 at 18:32
  • please edit your original question – Code-Apprentice Sep 27 '16 at 18:54
  • What is this `startApp()` method you refer to? – Code-Apprentice Sep 27 '16 at 18:56
  • I edited my question ;) – mcExchange Sep 27 '16 at 19:37
  • Presumably `downloader_ui.xml` had a progress bar. The official documentation describes how to track progress of the download. – Code-Apprentice Sep 27 '16 at 21:19
  • `startApp()` is probably a helper method which initializes your app. This probably contains the logic to read dates from the expansion file. – Code-Apprentice Sep 27 '16 at 21:22

0 Answers0