我有这个代码,我下载 APK扩展文件
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);
}
}
}
问题是我需要处理 回调 ,例如 onDownloadFinished 和 onProgressUpdate 即可。我知道有些消息是在某处发布的,但我不知道如何处理它们。由于我没有使用 Android 中的消息,任何帮助都会很好。
更新:
所有下载都在这里发生:
int result = DownloaderClientMarshaller.startDownloadServiceIfRequired(
this, pendingIntent, MyDownloaderService.class);
if (DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED != result) {
// implement Downloading UI.
return;
}
我猜这些回调必须连接到 DownloaderClientMarshaller 类。