Как исправить ошибку W/SQLiteLog: (28) failed to open

maptj.mbtiles находится в Internal storage

W/SQLiteLog: (28) failed to open "/storage/emulated/0/osmdroid/maptj.mbtiles" with flag (131072) and mode_t (0) due to error (13) E/SQLiteLog: (14) cannot open file at line 37509 of [c255889bd9] (14) os_unix.c:37509: (13) open(/storage/emulated/0/osmdroid/maptj.mbtiles) -

public class MainActivity extends AppCompatActivity {

private MapView mapView;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    Context ctx = getApplicationContext();
    Configuration.getInstance().load(ctx, PreferenceManager.getDefaultSharedPreferences(ctx));




    setContentView(R.layout.osm_map);

    mapView = (MapView) findViewById(R.id.map);


    String name = "maptj.mbtiles";
    File f = new File(Environment.getExternalStorageDirectory() + "/osmdroid", name);
    if (f.exists()) {
        try {

            //ok found a file we support and have a driver for the format, for this demo, we'll just use the first one

            //create the offline tile provider, it will only do offline file archives
            //again using the first file
            OfflineTileProvider tileProvider = new OfflineTileProvider(new SimpleRegisterReceiver(this),
                    new File[]{f});

            //tell osmdroid to use that provider instead of the default rig which is (asserts, cache, files/archives, online
            mapView.setTileProvider(tileProvider);

            //this bit enables us to find out what tiles sources are available. note, that this action may take some time to run
            //and should be ran asynchronously. we've put it inline for simplicity

            String source = "";
            IArchiveFile[] archives = tileProvider.getArchives();
            if (archives.length > 0) {
                //cheating a bit here, get the first archive file and ask for the tile sources names it contains
                Set<String> tileSources = archives[0].getTileSources();
                //presumably, this would be a great place to tell your users which tiles sources are available
                if (!tileSources.isEmpty()) {
                    //ok good, we found at least one tile source, create a basic file based tile source using that name
                    //and set it. If we don't set it, osmdroid will attempt to use the default source, which is "MAPNIK",
                    //which probably won't match your offline tile source, unless it's MAPNIK
                    source = tileSources.iterator().next();
                    mapView.setTileSource(FileBasedTileSource.getSource(source));
                } else {
                    mapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
                }

            } else {
                mapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
            }
            mapView.setUseDataConnection(false);

            mapView.setTileSource(new XYTileSource("MapquestOSM", 2, 15, 256, ".png", new String[]{}));
            mapView.setBuiltInZoomControls(true);
            IMapController mapController = mapView.getController();
            mapController.setZoom(10);
            GeoPoint startPt = new GeoPoint(38.5357,68.77905);
            mapController.setCenter(startPt);
            mapView.invalidate();
            return;
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }
}

}


Ответы (0 шт):