【问题标题】:IDownloaderClient onServiceConnected Not Being CalledIDownloaderClient onServiceConnected 未被调用
【发布时间】:2017-03-20 21:19:42
【问题描述】:

我正在尝试让我的应用在启动时下载扩展文件。我关注了guide from Android,有一段时间它会开始下载,然后在 98% 处停止,告诉我它无法验证文件,但文件确实在那里。今天,我没有更改任何代码,甚至没有尝试下载。我在整个班级都设置了断点,但它永远不会到达来自IDownloaderClientonServiceConnected 方法。

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,但由于某种原因它没有连接服务。就像我说的,这在几天前有效,我没有改变任何东西,但现在它不起作用了。

有什么帮助吗?

【问题讨论】:

    标签: android apk-expansion-files serviceconnection


    【解决方案1】:

    似乎您的服务类名称是DownloaderServiceHelper 所以需要修改initializeDownloadUi方法中的代码

    来自

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-30
      相关资源
      最近更新 更多