APK扩展文件-下载器库不支持Android Oreo和Android Studio版本3.2?

时间:2018-10-26 04:33:16

标签: android apk-expansion-files

我相信原始的APK扩展库的设计有些过分。而且不支持android Oreo。

  

第一:   我正在尝试使用Google的下载器库和应用程序许可服务,因为我的应用程序将使用APK扩展。   我从https://developer.android.com/google/play/expansion-files#javahttps://kitefaster.com/2017/02/15/expansion-apk-files-android-studio/阅读了指南,一切进展顺利。但是error.expansion.downloader不存在。我做了所有的指导   enter image description hereenter image description hereenter image description here

     

最终   ,我使用了git-hub https://github.com/bolein/better-apk-expansion中的lib   但是在下载OBB文件时,它始终状态为IDownloaderClient.STATE_FAILED_FETCHING_URL,并且它不支持Android Oreo,带有错误的Toast程序包的开发人员警告。无法在通道上发布通知。   代码下载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();
    }

我希望有人给我一个解决方案。


2 个答案:

答案 0 :(得分:1)

尝试从Github迁移到最新的扩展代码。 Google尚未更新其文档。代码位于:https://github.com/google/play-apk-expansion

答案 1 :(得分:0)

我真的不知道您的问题,但是我下面的代码使用play-apk-expansion并且工作正常。 请注意,在使用模拟器使用Google Play支持的图片时。

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


    }