问题描述
我有一个带有扩展名文件的apk.我正在按原样使用OBB压缩文件.我成功将其上传到Google Play,并且在下载时,扩展文件会自动下载.自动下载工作正常.OBB手册下载根本不起作用.我跟随Google开发人员页面导入了downloader_library& zip_file&也是license_library. https://developer.android.com/google/play/expansion-files. html
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
我的步骤:1-导入模块:下载器库,zip_file和市场许可.将2个示例下载程序类复制到我的程序包中(2个文件)(SampleDownloaderService和SampleAlarmReceiver).3实现的启动活动如下:
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
添加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
非常感谢您的帮助.
推荐答案
我猜您可能没有正确处理错误.您能否扩展问题以说出您在日志中看到的内容?
I'd guess you probably aren't handling errors properly. Can you expand your question to say what you see in the logs?
这篇关于应用程式扩充下载无法正常运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!