2

I have this code with wich I download APK expension file

private void performAPKExpansionCheckAndDownload(){
        String APK_LOG = "APK_LOG";
        String mainFileName = Helpers.getExpansionAPKFileName(this, true, 2);
        Log.d(APK_LOG,"mainFileName  "+mainFileName);
        boolean fileExists = Helpers.doesFileExist(this, mainFileName, 38783430L, false);
        Log.d(APK_LOG,"fileExists  "+fileExists);
        if (!fileExists) {
            Intent launcher = getIntent();
            Intent fromNotification = new Intent(this, getClass());
            fromNotification.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            fromNotification.setAction(launcher.getAction());
            if (launcher.getCategories() != null) {
                for (String cat : launcher.getCategories()) {
                    Log.d(APK_LOG,"cat  "+cat);
                    fromNotification.addCategory(cat);
                }
            }
            PendingIntent pendingIntent = PendingIntent.getActivity(
                    this, 0, fromNotification, PendingIntent.FLAG_UPDATE_CURRENT);
            try {
                int result = DownloaderClientMarshaller.startDownloadServiceIfRequired(
                        this, pendingIntent, MyDownloaderService.class);
                Log.d(APK_LOG,"result  "+result);
                if (DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED != result) {
                    // implement Downloading UI.
                    return;
                }
            } catch (NameNotFoundException e) {
                Log.e("apk-expansion-files", "NameNotFoundException occurred. " + e.getMessage(), e);
            }
        }
    }

The problem is that I need to handle callbacks like onDownloadFinished and onProgressUpdate. I know that thous messages are posted somewhere but I don't know how to handle them. Since I haven't worked with messages in Android any help would be good.

UPDATE:

All downloading happens here:

int result = DownloaderClientMarshaller.startDownloadServiceIfRequired(
                         this, pendingIntent, MyDownloaderService.class);
if (DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED != result) {
    // implement Downloading UI.
    return;
}

I guess those callbacks must be connected to that DownloaderClientMarshaller class.

4

0 回答 0