App Expansion下载无效

时间:2018-01-26 22:07:54

标签: android apk-expansion-files

我有一个带有扩展名文件的apk。我按原样使用OBB压缩文件。我成功将其上传到谷歌播放,下载时,会自动下载扩展文件。自动下载工作正常。 OBB手动下载根本不起作用。 我按照谷歌开发者页面导入downloader_library& zip_file& license_library也是。 https://developer.android.com/google/play/expansion-files.html

我的步骤: 1 - 导入模块:下载程序库,zip_file和市场许可证。 2个复制的样本下载程序类到我的包(2个文件)(SampleDownloaderService和SampleAlarmReceiver)。 3实现的启动活动如下:

public class SplashActivity extends Activity implements IDownloaderClient {

int SPLASH_DURATION = 1000;

// APK EXPANSIONS
private IStub mDownloaderClientStub;
private IDownloaderService mRemoteService;
private ProgressDialog mProgressDialog;
private static final String LOG_TAG = "Checking_download";

// The shared path to all app expansion files


private static class XAPKFile {
    public final boolean mIsMain;
    public final int mFileVersion;
    public final long mFileSize;

    XAPKFile(boolean isMain, int fileVersion, long fileSize) {
        mIsMain = isMain;
        mFileVersion = fileVersion;
        mFileSize = fileSize;
    }
}

private static final XAPKFile[] xAPKS = {
        new XAPKFile(
                true, // true signifies a main file
                2, // the version of the APK that the file was uploaded against
                91668074L // the length of the file in bytes
        )
};

boolean expansionFilesDelivered() {
    for (XAPKFile xf : xAPKS) {
        String fileName = Helpers.getExpansionAPKFileName(this, xf.mIsMain, xf.mFileVersion);
         Log.e(LOG_TAG, "XAPKFile name : " + fileName);
        if (!Helpers.doesFileExist(this, fileName, xf.mFileSize, false)) {
            Log.e(LOG_TAG, "ExpansionAPKFile doesn't exist or has a wrong size (" + fileName + ", file size should be :"+  xf.mFileSize );
            return false;
        }
    }
    return true;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);


    // Check if expansion files are available before going any further
    if (!expansionFilesDelivered()) {
        Log.e(LOG_TAG, " expansion not delivered");
        try {
            Intent launchIntent = this.getIntent();

            // Build an Intent to start this activity from the Notification
            Intent notifierIntent = new Intent(SplashActivity.this, SplashActivity.this.getClass());
            notifierIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            notifierIntent.setAction(launchIntent.getAction());
            Log.e(LOG_TAG, " try intent");

            if (launchIntent.getCategories() != null) {
                Log.e(LOG_TAG, " intented launched");

                for (String category : launchIntent.getCategories()) {
                    notifierIntent.addCategory(category);
                    Log.e(LOG_TAG, " Category is" + category);

                }
            }

            PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notifierIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            // Start the download service (if required)
            Log.e(LOG_TAG, "Start the download service");
            int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this, pendingIntent, SampleDownloaderService.class);

            // If download has started, initialize activity to show progress
            if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
                Log.e(LOG_TAG, "initialize activity to show progress , result is: "+ startResult);
                // Instantiate a member instance of IStub
                mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, SampleDownloaderService.class);
                // Shows download progress
                mProgressDialog = new ProgressDialog(SplashActivity.this);
                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                mProgressDialog.setMessage(getResources().getString(R.string.state_downloading));
                mProgressDialog.setCancelable(false);
                mProgressDialog.show();
                return;
            }
            // If the download wasn't necessary, fall through to start the app
            else {
                Log.e(LOG_TAG, "No download required");
            }
        }
        catch (PackageManager.NameNotFoundException e) {
            Log.e(LOG_TAG, "Cannot find own package! MAYDAY!");
            e.printStackTrace();
        }
        catch (Exception e) {
            Log.e(LOG_TAG, e.getMessage());
            e.printStackTrace();
        }

    }
    else
    {
        // 2sec handler
        Log.e(LOG_TAG," 2nd handler");
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                startActivity(new Intent(SplashActivity.this, MainActivity2.class));
                finish();
            }
        }, SPLASH_DURATION);
    }

    // Set by <content src="index.html" /> in config.xml
    //super.loadUrl(Config.getStartUrl());
    //super.loadUrl("file:///android_asset/www/index.html")

}

@Override
protected void onStart() {
    if (null != mDownloaderClientStub) {
        mDownloaderClientStub.connect(this);
    }
    super.onStart();
}


@Override
protected void onResume() {
    if (null != mDownloaderClientStub) {
        mDownloaderClientStub.connect(this);
        Log.e(LOG_TAG, "service_resume : ");
    }
    super.onResume();
}

@Override
protected void onStop() {
    if (null != mDownloaderClientStub) {
        mDownloaderClientStub.disconnect(this);
        Log.e(LOG_TAG, "service_stopped : ");
    }
    super.onStop();
}

@Override
public void onServiceConnected(Messenger m) {
    Log.e(LOG_TAG, "service_to_connected : ");
    mRemoteService = DownloaderServiceMarshaller.CreateProxy(m);
    mRemoteService.onClientUpdated(mDownloaderClientStub.getMessenger());
    Log.e(LOG_TAG, "service_connected : ");
}

@Override
public void onDownloadStateChanged(int newState) {
    Log.e(LOG_TAG, "DownloadStateChanged : " + getString(Helpers.getDownloaderStringResourceIDFromState(newState)));

    switch (newState) {
        case STATE_DOWNLOADING:
            Log.e(LOG_TAG, "Downloading...");
            break;
        case STATE_COMPLETED: // The download was finished
            // validateXAPKZipFiles();
            mProgressDialog.setMessage("");
            // dismiss progress dialog
            mProgressDialog.dismiss();
            // Load url
            //super.loadUrl(Config.getStartUrl());
            break;
        case STATE_FAILED_UNLICENSED:
        case STATE_FAILED_FETCHING_URL:
        case STATE_FAILED_SDCARD_FULL:
        case STATE_FAILED_CANCELED:
        case STATE_FAILED:
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
            alert.setTitle("error");
            alert.setMessage("download failed");
            alert.setNeutralButton("close", null);
            alert.show();
            break;
    }
}

@Override
public void onDownloadProgress(DownloadProgressInfo progress) {
    long percents = progress.mOverallProgress * 100 / progress.mOverallTotal;
    Log.e(LOG_TAG, "DownloadProgress:"+Long.toString(percents) + "%");
    mProgressDialog.setProgress((int) percents);
}

}

结果: 我没有进展就得到了图片。即使我没有连接到互联网,我也会得到相同的结果。即使我等了一个小时,也没有变化。 enter image description here

添加logcat:

I/CachedDir: file changed, refill cache - 1357
E/Checking_download:  expansion not delivered
E/Checking_download:  try intent
E/Checking_download:  intented launched
E/Checking_download:  Category isandroid.intent.category.LAUNCHER
E/Checking_download: Start the download service
E/Checking_download: initialize activity to show progress , result is: 2
I/View: ssignParent(ViewParent parent) parent is: android.view.ViewRootImpl@244ce5ae
E/Checking_download: service_resume : 
I/View: ssignParent(ViewParent parent) parent is: android.view.ViewRootImpl@104416b
I/OpenGLRenderer: Initialized EGL, version 1.4

非常感谢你的帮助。

1 个答案:

答案 0 :(得分:0)

我猜你可能没有正确处理错误。你可以扩展你的问题来说出你在日志中看到的内容吗?