0

我试图让我的应用程序在启动时下载扩展文件。我按照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,但由于某种原因它没有连接服务。就像我说的,这在几天前有效,我没有改变任何东西,但现在它不起作用。

有什么帮助吗?

4

1 回答 1

0

好像您的服务类名称是DownloaderServiceHelper 所以您需要更改initializeDownloadUi方法中的代码

mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, DownloaderService.class);

mDownloaderClientStub = DownloaderClientMarshaller.CreateStub(this, DownloaderServiceHelper.class);

于 2017-06-08T14:36:12.487 回答