我试图让我的应用程序在启动时下载扩展文件。我跟着guide from Android,有一段时间它会开始下载,然后停在98%告诉我它无法验证文件,但文件实际上就在那里。今天,我还没有改变任何代码,甚至没有尝试下载。我在整个课程中都设置了断点,但它永远不会使用来自IDownloaderClient
的{{1}}方法。
在 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,但由于某种原因,它无法连接该服务。就像我说的那样,这是几天前的工作,我没有改变任何东西,但现在它没有用。
任何帮助?
答案 0 :(得分:0)
似乎您的服务类名称为DownloaderServiceHelper
因此,您需要更改initializeDownloadUi
方法
这
mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, DownloaderService.class);
到
mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, DownloaderServiceHelper.class);