问题
I have an apk with an extension file. I am using the OBB zipped file as is. I succeeded to upload it to google play, and when downloading, the extension file is downloaded automatically. automatic download is working fine. The OBB manual download is not working at all. I followed google developer page to import downloader_library & zip_file & also license_library. https://developer.android.com/google/play/expansion-files.html
My steps: 1-Import modules : downloader library, zip_file and market license. 2-copied sample downloader classes to my package ( 2 files) (SampleDownloaderService and SampleAlarmReceiver). 3-implemented splash activity as below:
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);
}
}
the result: I get below picture without progress. even if i'm not connected to internet I get same result. even if I wait for one hour, no change. enter image description here
adding the 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
Thanks very much for your help.
回答1:
I'd guess you probably aren't handling errors properly. Can you expand your question to say what you see in the logs?
来源:https://stackoverflow.com/questions/48470278/app-expansion-download-not-working