From df669fcd9dbdd16ed2591c7b39b242e9c293fbdd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 23 Jun 2021 21:29:13 -0700 Subject: Implement location support --- app/src/main/AndroidManifest.xml | 1 + .../java/org/traccar/manager/MainActivity.java | 15 ++++++- .../java/org/traccar/manager/MainFragment.java | 49 ++++++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 41cbaf6..7931b2b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ package="org.traccar.manager"> + 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED; + if (geolocationCallback != null) { + geolocationCallback.invoke(geolocationRequestOrigin, granted, false); + geolocationRequestOrigin = null; + geolocationCallback = null; + } + } + } + + private String geolocationRequestOrigin; + private GeolocationPermissions.Callback geolocationCallback; + private final WebChromeClient webChromeClient = new WebChromeClient() { + @Override + public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { + geolocationRequestOrigin = null; + geolocationCallback = null; + if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + if (ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION)) { + new AlertDialog.Builder(getActivity()) + .setMessage(R.string.permission_location_rationale) + .setNeutralButton(android.R.string.ok, (dialog, which) -> { + geolocationRequestOrigin = origin; + geolocationCallback = callback; + ActivityCompat.requestPermissions( + getActivity(), new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_PERMISSIONS_LOCATION); + }) + .show(); + } else { + geolocationRequestOrigin = origin; + geolocationCallback = callback; + ActivityCompat.requestPermissions( + getActivity(), new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, REQUEST_PERMISSIONS_LOCATION); + } + } else { + callback.invoke(origin, true, false); + } + } + // Android 4.1+ protected void openFileChooser(ValueCallback uploadMessage, String acceptType, String capture) { openFileChooser(uploadMessage); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2ae7947..feea781 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -6,4 +6,5 @@ Server connection failed File Browser Default + App requires location permission to show current location on the map -- cgit v1.2.3