首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IDownloaderClient onServiceConnected未被调用

IDownloaderClient onServiceConnected未被调用
EN

Stack Overflow用户
提问于 2017-03-20 21:19:42
回答 1查看 176关注 0票数 0

我正在尝试让我的应用程序在启动时下载扩展文件。我跟踪了Android指南,有一段时间它将开始下载,然后以98%的速度停止,告诉我它无法验证该文件,但文件实际上就在那里。今天,我没有修改任何代码,它甚至没有尝试下载。我在整个类中都放置了断点,而且它永远不会到达来自onServiceConnectedIDownloaderClient方法。

onCreate的末尾

代码语言:javascript
复制
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()

代码语言:javascript
复制
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

代码语言:javascript
复制
if (null != mDownloaderClientStub) {
    mDownloaderClientStub.connect(this);
}

super.onResume();

它像预期的那样通过onCreate,但是由于某种原因它没有连接到服务。就像我说的,这几天前起作用了,我什么也没改变,但现在它不起作用了。

有什么帮助吗?

EN

回答 1

Stack Overflow用户

发布于 2017-06-08 14:36:12

您的服务类名似乎是DownloaderServiceHelper,因此您需要更改initializeDownloadUi方法中的代码

从…

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42914168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档