我相信最初的APK扩展库略微过度设计。而且不支持android Oreo。
第一:我正在尝试使用谷歌的下载程序库和应用程序许可服务,因为我的应用程序将使用APK扩展。我读了https://developer.android.com/google/play/expansion-files#java和https://kitefaster.com/2017/02/15/expansion-apk-files-android-studio/的指南,一切都很顺利。但是error.expansion.downloader不存在。我做了一切作为指导enter image description here,enter image description here,enter image description here
最后,我使用了来自git-hub https://github.com/bolein/better-apk-expansion的lib但是它总是在下载OBB文件时状态IDownloaderClient.STATE_FAILED_FETCHING_URL并且它不支持Android Oreo并且错误toast Developer警告包无法在通道上发布通知。代码下载OBB文件:
if (!expansionFilesDelivered()) {
try {
Intent launchIntent = SampleDownloaderActivity.this
.getIntent();
Intent intentToLaunchThisActivityFromNotification = new Intent(
SampleDownloaderActivity
.this, SampleDownloaderActivity.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(
SampleDownloaderActivity.this,
0, intentToLaunchThisActivityFromNotification,
PendingIntent.FLAG_UPDATE_CURRENT);
// Request to start the download
int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
pendingIntent, SampleDownloaderService.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();
}
} else {
validateXAPKZipFiles();
}
我希望有人能给我一个解决方案。
尝试从Github转移到最新的扩展代码。谷歌还没有更新他们的文档。代码位于:https://github.com/google/play-apk-expansion
我真的不知道你的问题,但我的下面的代码使用play-apk-expansion并且工作正常。请注意,使用模拟器时使用谷歌播放支持的图像。
void check_apkx(){
if (!expansionFilesDelivered()) {
try {
Intent launchIntent = MainActivity.this.getIntent();
Intent intentToLaunchThisActivityFromNotification = new Intent(
MainActivity.this, MainActivity.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(
MainActivity.this,
0, intentToLaunchThisActivityFromNotification,
PendingIntent.FLAG_UPDATE_CURRENT);
// Request to start the download
DownloaderClientMarshaller.startDownloadServiceIfRequired(this,
pendingIntent, SampleDownloaderService.class);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
} else {
// validateXAPKZipFiles();
}