From 45545e15fc41d5beb98612736ee624272b192096 Mon Sep 17 00:00:00 2001 From: Tobrun Date: Mon, 8 May 2017 12:07:00 +0200 Subject: [PATCH] [android] - show error message when no browser is installed on the device of the user. (#8901) --- .../maps/AttributionDialogManager.java | 26 ++++++++++++------- .../src/main/res/values/strings.xml | 1 + 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java index 2ae37acb9c5..5113a0cc732 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/AttributionDialogManager.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.maps; +import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -12,6 +13,7 @@ import android.text.style.URLSpan; import android.view.View; import android.widget.ArrayAdapter; +import android.widget.Toast; import com.mapbox.mapboxsdk.R; import com.mapbox.mapboxsdk.camera.CameraPosition; @@ -66,7 +68,7 @@ public void onClick(DialogInterface dialog, int which) { if (isLatestEntry(which)) { showTelemetryDialog(); } else { - showAttributionWebPage(which); + showMapFeedbackWebPage(which); } } @@ -88,10 +90,7 @@ public void onClick(DialogInterface dialog, int which) { builder.setNeutralButton(R.string.mapbox_attributionTelemetryNeutral, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - String url = context.getResources().getString(R.string.mapbox_telemetryLink); - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(url)); - context.startActivity(intent); + showWebPage(context.getResources().getString(R.string.mapbox_telemetryLink)); dialog.cancel(); } }); @@ -105,14 +104,12 @@ public void onClick(DialogInterface dialog, int which) { builder.show(); } - private void showAttributionWebPage(int which) { - Intent intent = new Intent(Intent.ACTION_VIEW); + private void showMapFeedbackWebPage(int which) { String url = attributionMap.get(attributionKeys[which]); if (url.contains(MAP_FEEDBACK_URL)) { url = buildMapFeedbackMapUrl(mapboxMap.getCameraPosition()); } - intent.setData(Uri.parse(url)); - context.startActivity(intent); + showWebPage(url); } private String buildMapFeedbackMapUrl(CameraPosition cameraPosition) { @@ -122,6 +119,17 @@ private String buildMapFeedbackMapUrl(CameraPosition cameraPosition) { (int) cameraPosition.zoom) : MAP_FEEDBACK_URL; } + private void showWebPage(@NonNull String url) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse(url)); + context.startActivity(intent); + } catch (ActivityNotFoundException exception) { + // explicitly handling if the device hasn't have a web browser installed. #8899 + Toast.makeText(context, R.string.mapbox_attributionErrorNoBrowser, Toast.LENGTH_LONG).show(); + } + } + private static class AttributionBuilder { private final HashMap map = new LinkedHashMap<>(); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml index 6c427d540b4..0862305cfbc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/strings.xml @@ -10,6 +10,7 @@ Agree Disagree More info + No web browser installed on device, can\'t open web page. Provided OfflineRegionDefinition doesn\'t fit the world bounds: %s Telemetry Settings https://www.mapbox.com/telemetry/