我正在尝试让我的应用程序在启动时下载扩展文件。我跟踪了Android指南,有一段时间它将开始下载,然后以98%的速度停止,告诉我它无法验证该文件,但文件实际上就在那里。今天,我没有修改任何代码,它甚至没有尝试下载。我在整个类中都放置了断点,而且它永远不会到达来自onServiceConnected的IDownloaderClient方法。
在onCreate的末尾
initializeDownloadUI();
if (!expansionFilesDelivered()) {
try {
final Intent launchIntent = MainActivity.this.getIntent();
final 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.
final PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intentToLaunchThisActivityFromNotification, PendingIntent.FLAG_UPDATE_CURRENT);
// Request to start the download.
final int startResult = DownloaderClientMarshaller.startDownloadServiceIfRequired(this, pendingIntent, DownloaderServiceHelper.class);
if (startResult != DownloaderClientMarshaller.NO_DOWNLOAD_REQUIRED) {
initializeDownloadUI();
return;
}
} catch (PackageManager.NameNotFoundException exc) {
Log.wtf("MainActivity", "Cannot find own package.");
exc.printStackTrace();
}
} else validateXAPKZipFiles();我的initializeDownloadUI()是
mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, DownloaderService.class);
setContentView(R.layout.main);
mPB = (ProgressBar) findViewById(R.id.progressBar);
mStatusText = (TextView) findViewById(R.id.statusText);
mProgressFraction = (TextView) findViewById(R.id.progressAsFraction);
mProgressPercent = (TextView) findViewById(R.id.progressAsPercentage);
mAverageSpeed = (TextView) findViewById(R.id.progressAverageSpeed);
mTimeRemaining = (TextView) findViewById(R.id.progressTimeRemaining);
mDashboard = findViewById(R.id.downloaderDashboard);
mCellMessage = findViewById(R.id.approveCellular);
mPauseButton = (Button) findViewById(R.id.pauseButton);
mWiFiSettingButton = (Button) findViewById(R.id.wifiSettingsButton);
mPauseButton.setOnClickListener(this);
mWiFiSettingButton.setOnClickListener(this);
(findViewById(R.id.resumeOverCellular)).setOnClickListener(this);另外,我的onResume是
if (null != mDownloaderClientStub) {
mDownloaderClientStub.connect(this);
}
super.onResume();它像预期的那样通过onCreate,但是由于某种原因它没有连接到服务。就像我说的,这几天前起作用了,我什么也没改变,但现在它不起作用了。
有什么帮助吗?
发布于 2017-06-08 14:36:12
您的服务类名似乎是DownloaderServiceHelper,因此您需要更改initializeDownloadUi方法中的代码
从…
mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, DownloaderService.class);
至
mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, DownloaderServiceHelper.class);
https://stackoverflow.com/questions/42914168
复制相似问题