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