MapBox下载离线区域停留在99.9%

时间:2017-03-08 05:43:37

标签: android mapbox

当我下载地图时,它说我需要1299个资源来完成它。但是当项目数达到1298/1299时。它被卡住了。基本上它总是停留在99.9%。离线地图是可见且可用的,但我的用户界面和我的下载服务永远等待onStatusChanged()上的回调达到100%。

在调试器上,我收到了这个日志:

03-10 09:19:10.034 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 98.84526558891454% items 1284/1299
03-10 09:19:10.054 23981-29834/com.indigo.android.shoreleave V/com.mapbox.mapboxsdk.http.HTTPRequest: [HTTP] Request was successful (code = 200).
03-10 09:19:10.054 23981-29860/com.indigo.android.shoreleave V/com.mapbox.mapboxsdk.http.HTTPRequest: [HTTP] Request was successful (code = 200).
03-10 09:19:10.064 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 98.92224788298691% items 1285/1299
03-10 09:19:10.064 23981-29858/com.indigo.android.shoreleave V/com.mapbox.mapboxsdk.http.HTTPRequest: [HTTP] Request was successful (code = 200).
03-10 09:19:10.074 23981-30075/com.indigo.android.shoreleave V/com.mapbox.mapboxsdk.http.HTTPRequest: [HTTP] Request was successful (code = 200).
03-10 09:19:10.134 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 98.99923017705927% items 1286/1299
03-10 09:19:10.154 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.07621247113164% items 1287/1299
03-10 09:19:10.184 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.153194765204% items 1288/1299
03-10 09:19:10.214 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.23017705927637% items 1289/1299
03-10 09:19:10.254 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.30715935334872% items 1290/1299
03-10 09:19:10.274 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.38414164742109% items 1291/1299
03-10 09:19:10.304 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.46112394149345% items 1292/1299
03-10 09:19:10.334 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.53810623556582% items 1293/1299
03-10 09:19:10.374 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.61508852963819% items 1294/1299
03-10 09:19:10.454 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.69207082371055% items 1295/1299
03-10 09:19:10.484 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.7690531177829% items 1296/1299
03-10 09:19:10.514 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.84603541185527% items 1297/1299
03-10 09:19:10.564 23981-23981/com.indigo.android.shoreleave I/ShoreLeaveApplication: From service: Downloading id 1@ 99.92301770592763% items 1298/1299
03-10 09:19:20.604 23981-27396/com.indigo.android.shoreleave D/GzipRequestInterceptor: Compressing
03-10 09:19:22.564 23981-27396/com.indigo.android.shoreleave D/MapboxEventManager: response code = 204 for events 2

日志太长,但我只从90-99.9获取日志。从日志末尾(99.9%,1298/1299)可以看出,它说:

D/GzipRequestInterceptor: Compressing
    03-10 09:19:22.564 23981-27396/com.indigo.android.shoreleave D/MapboxEventManager: response code = 204 for events 2

这是我的代码:

private OfflineManager.CreateOfflineRegionCallback mOnCreateOfflineRegionCallback = new OfflineManager.CreateOfflineRegionCallback()
{
    @Override
    public void onCreate(final OfflineRegion offlineRegion)
    {
        offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE);
        offlineRegion.setObserver(new OfflineRegion.OfflineRegionObserver()
        {
            @Override
            public void onStatusChanged(OfflineRegionStatus status)
            {
                double percentage = status.getRequiredResourceCount() >= 0 ? (100.0 * status.getCompletedResourceCount() / status.getRequiredResourceCount()) : 0.0;
                long mapID = offlineRegion.getID();

                Intent intent = new Intent();
                intent.putExtra(Extras.MAP_DOWNLOAD_ID, mapID);
                intent.putExtra(Extras.DOWNLOAD_PERCENTAGE, percentage);
                intent.putExtra(Extras.DOWNLOAD_REQUIRED_RESOURCE_COUNT, status.getRequiredResourceCount());
                intent.putExtra(Extras.DOWNLOAD_COMPLETED_RESOURCE_COUNT, status.getCompletedResourceCount());
                intent.putExtra(Extras.IS_DOWNLOAD_COMPLETE, status.isComplete());
                intent.putExtra(Extras.IS_DOWNLOAD_STEP_SUCCESS, true);
                intent.putExtra(Extras.IS_DOWNLOAD_FAILED, false);
                intent.putExtra(Extras.DOWNLOAD_STATE, status.getDownloadState());

                mIsFinished.put(mapID, status.isComplete());

                try
                {
                    JSONObject jsonObject = new JSONObject(new String(offlineRegion.getMetadata(), Charset.forName("UTF-8")));
                    intent.putExtra(Extras.MAP_NAME, jsonObject.getString(Extras.MAP_NAME));
                }
                catch (JSONException e)
                {
                    e.printStackTrace();
                }

                ShoreLeaveCacheManager.insertOrUpdate(Utils.getDownloadStatusFromIntent(intent));

                createOrUpdateNotification(intent);

                if(mOnDownloadCallback != null)
                    mOnDownloadCallback.onDownloadProgress(intent);

                if(mIsFinished.containsKey(mapID) && mIsFinished.get(mapID))
                    ShoreLeaveCacheManager.save(OfflineMapDownloadService.this.getApplicationContext(), ShoreLeaveCacheManager.CACHE_DOWNLOAD_STATUS);

                if(isAllDownloadFinished())
                {
                    stop();
                    mHasStarted = false;
                }

                Log.i(ShoreLeaveApplication.TAG, "From service: Downloading id "
                    + mapID + "@ " + percentage
                    + "% items " + status.getCompletedResourceCount()
                    + "/" + status.getRequiredResourceCount());
            }

            @Override
            public void onError(OfflineRegionError error)
            {
                Intent intent = new Intent(Constants.BROADCAST_OFFLINE_MAP_DOWNLOAD_STATUS);
                intent.putExtra(Extras.MAP_DOWNLOAD_ID, offlineRegion.getID());
                intent.putExtra(Extras.IS_DOWNLOAD_COMPLETE, false);
                intent.putExtra(Extras.IS_DOWNLOAD_STEP_SUCCESS, false);
                intent.putExtra(Extras.IS_DOWNLOAD_FAILED, true);
                intent.putExtra(Extras.DOWNLOAD_STATE, OfflineRegion.STATE_INACTIVE);

                ShoreLeaveCacheManager.insertOrUpdate(Utils.getDownloadStatusFromIntent(intent));
                ShoreLeaveCacheManager.save(OfflineMapDownloadService.this.getApplicationContext(), ShoreLeaveCacheManager.CACHE_DOWNLOAD_STATUS);
                mIsFinished.remove(offlineRegion.getID());
                createOrUpdateNotification(intent);

                // LocalBroadcastManager.getInstance(OfflineMapDownloadService.this.getBaseContext()).sendBroadcast(intent);
                if(mOnDownloadCallback != null) mOnDownloadCallback.onDownloadProgress(intent);

                if(isAllDownloadFinished())
                {
                    stop();
                    mHasStarted = false;
                }

                mNotificationManager.notify(1000 + ((int) offlineRegion.getID()), Utils.buildOfflineMapDownloadServiceNotification(OfflineMapDownloadService.this, intent, "Failed... "));
            }

            @Override
            public void mapboxTileCountLimitExceeded(long limit)
            {
                Intent intent = new Intent(Constants.BROADCAST_OFFLINE_MAP_DOWNLOAD_STATUS);
                intent.putExtra(Extras.MAP_DOWNLOAD_ID, offlineRegion.getID());
                intent.putExtra(Extras.IS_DOWNLOAD_COMPLETE, false);
                intent.putExtra(Extras.IS_DOWNLOAD_STEP_SUCCESS, false);
                intent.putExtra(Extras.IS_DOWNLOAD_FAILED, true);
                intent.putExtra(Extras.DOWNLOAD_STATE, OfflineRegion.STATE_INACTIVE);

                ShoreLeaveCacheManager.insertOrUpdate(Utils.getDownloadStatusFromIntent(intent));
                ShoreLeaveCacheManager.save(OfflineMapDownloadService.this.getApplicationContext(), ShoreLeaveCacheManager.CACHE_DOWNLOAD_STATUS);
                mIsFinished.remove(offlineRegion.getID());

                // LocalBroadcastManager.getInstance(OfflineMapDownloadService.this.getBaseContext()).sendBroadcast(intent);
                if(mOnDownloadCallback != null)
                    mOnDownloadCallback.onDownloadProgress(intent);

                if(isAllDownloadFinished())
                {
                    stop();
                    mHasStarted = false;
                }

                mNotificationManager.notify(1000 + ((int) offlineRegion.getID()), Utils.buildOfflineMapDownloadServiceNotification(OfflineMapDownloadService.this, intent, "Failed... "));
            }
        });

        if(mOnDownloadCallback != null)
            mOnDownloadCallback.onOfflineRegionCreated(offlineRegion);
    }

    @Override
    public void onError(String error)
    {
        // LocalBroadcastManager.getInstance(OfflineMapDownloadService.this).sendBroadcast(new Intent(Constants.BROADCAST_OFFLINE_MAP_DOWNLOAD_STATUS));
    }
};

如果这是我的结果。可能只是一个错误。我还在检查。如果没有,这是正常的吗?有什么想法吗?

1 个答案:

答案 0 :(得分:1)

这不正常,您是否可以提供更多日志输出,以便我可以更好地解决问题。