diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java index 2389467..095beb4 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java @@ -17,13 +17,20 @@ import java.util.List; import java.util.zip.GZIPOutputStream; import java.util.ArrayList; +import android.Manifest; import android.app.Service; import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Build; import android.os.Bundle; +import android.os.Environment; import android.os.IBinder; import android.os.RemoteException; import android.util.Log; import android.util.Base64; + +import androidx.core.content.ContextCompat; + import btools.router.OsmNodeNamed; public class BRouterService extends Service @@ -203,7 +210,13 @@ public class BRouterService extends Service // add nogos from waypoint database int deviceLevel = android.os.Build.VERSION.SDK_INT; int targetSdkVersion = getApplicationInfo().targetSdkVersion; - boolean canAccessSdCard = deviceLevel < 23 || targetSdkVersion == 19; + boolean canAccessSdCard = true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !Environment.isExternalStorageLegacy()) { + canAccessSdCard = false; + } + if (ContextCompat.checkSelfPermission(BRouterService.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + canAccessSdCard = false; + } AppLogger.log( "dev/target=" + deviceLevel + "/" + targetSdkVersion + " canAccessSdCard=" + canAccessSdCard ); if ( canAccessSdCard ) { @@ -211,18 +224,13 @@ public class BRouterService extends Service worker.nogoList = new ArrayList( cor.nogopoints ); worker.nogoPolygonsList = new ArrayList(); } - else if (deviceLevel >= android.os.Build.VERSION_CODES.Q) { + else { CoordinateReader cor = new CoordinateReaderInternal( baseDir ); cor.readFromTo(); worker.nogoList = new ArrayList( cor.nogopoints ); worker.nogoPolygonsList = new ArrayList(); } - else - { - worker.nogoList = new ArrayList(); - worker.nogoPolygonsList = new ArrayList(); - } } diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java index dd39382..1bc0d44 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java @@ -222,20 +222,21 @@ public class BRouterView extends View waitingForMigration = false; } - int deviceLevel = android.os.Build.VERSION.SDK_INT; + int deviceLevel = Build.VERSION.SDK_INT; int targetSdkVersion = getContext().getApplicationInfo().targetSdkVersion; - canAccessSdCard = deviceLevel < 23 || targetSdkVersion == 19; - if ( canAccessSdCard ) - { - cor = CoordinateReader.obtainValidReader( basedir, segmentDir ); + canAccessSdCard = true; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && !Environment.isExternalStorageLegacy()) { + canAccessSdCard = false; } - else - { - if (deviceLevel >= android.os.Build.VERSION_CODES.Q) { - cor = new CoordinateReaderInternal(basedir); - } else { - cor = new CoordinateReaderNone(); - } + if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + canAccessSdCard = false; + } + + if (canAccessSdCard) { + cor = CoordinateReader.obtainValidReader(basedir, segmentDir); + } + else { + cor = new CoordinateReaderInternal(basedir); cor.readFromTo(); }