forked from upstream-mirrors/OpenTracks
Catch ActivityNotFound exception for starting geo-data intents.
This commit is contained in:
@@ -42,7 +42,6 @@ import androidx.loader.content.Loader;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.Track;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
||||||
import de.dennisguse.opentracks.content.WaypointsColumns;
|
import de.dennisguse.opentracks.content.WaypointsColumns;
|
||||||
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment;
|
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment;
|
||||||
@@ -284,9 +283,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
switch (itemId) {
|
switch (itemId) {
|
||||||
case R.id.list_context_menu_show_on_map:
|
case R.id.list_context_menu_show_on_map:
|
||||||
if (markerIds.length == 1) {
|
if (markerIds.length == 1) {
|
||||||
Waypoint marker = contentProviderUtils.getWaypoint(markerIds[0]);
|
IntentUtils.showCoordinateOnMap(this, contentProviderUtils.getWaypoint(markerIds[0]));
|
||||||
intent = IntentUtils.newShowCoordinateOnMapIntent(marker);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_edit:
|
case R.id.list_context_menu_edit:
|
||||||
|
|||||||
@@ -316,8 +316,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
Log.e(TAG, "Not implemented");
|
Log.e(TAG, "Not implemented");
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_show_on_map:
|
case R.id.list_context_menu_show_on_map:
|
||||||
intent = IntentUtils.newShowCoordinateOnMapIntent((double) item.get(MARKER_LATITUDE_FIELD), (double) item.get(MARKER_LONGITUDE_FIELD), item.get(NAME_FIELD) + "");
|
IntentUtils.showCoordinateOnMap(this, (double) item.get(MARKER_LATITUDE_FIELD), (double) item.get(MARKER_LONGITUDE_FIELD), item.get(NAME_FIELD) + "");
|
||||||
startActivity(intent);
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_edit:
|
case R.id.list_context_menu_edit:
|
||||||
if (markerId != null) {
|
if (markerId != null) {
|
||||||
|
|||||||
@@ -190,8 +190,7 @@ public class MarkerDetailFragment extends Fragment {
|
|||||||
Intent intent;
|
Intent intent;
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.marker_detail_show_on_map:
|
case R.id.marker_detail_show_on_map:
|
||||||
intent = IntentUtils.newShowCoordinateOnMapIntent(waypoint);
|
IntentUtils.showCoordinateOnMap(getContext(), waypoint);
|
||||||
startActivity(intent);
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.marker_detail_edit:
|
case R.id.marker_detail_edit:
|
||||||
intent = IntentUtils.newIntent(fragmentActivity, MarkerEditActivity.class)
|
intent = IntentUtils.newIntent(fragmentActivity, MarkerEditActivity.class)
|
||||||
|
|||||||
@@ -64,10 +64,6 @@ public class IntentUtils {
|
|||||||
|
|
||||||
private static final String JPEG_EXTENSION = "jpeg";
|
private static final String JPEG_EXTENSION = "jpeg";
|
||||||
|
|
||||||
public static Intent newShowCoordinateOnMapIntent(Waypoint waypoint) {
|
|
||||||
return newShowCoordinateOnMapIntent(waypoint.getLocation().getLatitude(), waypoint.getLocation().getLongitude(), waypoint.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an intent to share a track file with an app.
|
* Creates an intent to share a track file with an app.
|
||||||
*
|
*
|
||||||
@@ -90,7 +86,11 @@ public class IntentUtils {
|
|||||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Intent newShowCoordinateOnMapIntent(double latitude, double longitude, String label) {
|
public static void showCoordinateOnMap(Context context, Waypoint waypoint) {
|
||||||
|
showCoordinateOnMap(context, waypoint.getLocation().getLatitude(), waypoint.getLocation().getLongitude(), waypoint.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showCoordinateOnMap(Context context, double latitude, double longitude, String label) {
|
||||||
//SEE https://developer.android.com/guide/components/intents-common.html#Maps
|
//SEE https://developer.android.com/guide/components/intents-common.html#Maps
|
||||||
String uri = "geo:0,0?q=" + latitude + "," + longitude;
|
String uri = "geo:0,0?q=" + latitude + "," + longitude;
|
||||||
if (label != null && label.length() > 0) {
|
if (label != null && label.length() > 0) {
|
||||||
@@ -98,7 +98,12 @@ public class IntentUtils {
|
|||||||
}
|
}
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
intent.setData(Uri.parse(uri));
|
intent.setData(Uri.parse(uri));
|
||||||
return intent;
|
|
||||||
|
try {
|
||||||
|
context.startActivity(intent);
|
||||||
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Toast.makeText(context, context.getString(R.string.app_not_installed_show_on_map), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,7 +125,7 @@ public class IntentUtils {
|
|||||||
try {
|
try {
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
Toast.makeText(context, "No app installed that can show the tracks on a map.", Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, context.getString(R.string.app_not_installed_show_on_map), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -304,7 +304,11 @@ limitations under the License.
|
|||||||
wind surfing
|
wind surfing
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<!-- Description -->
|
<string name="app_not_installed_show_on_map" translation_description="When 'show on map' is used and no app with this functionality is installed.">
|
||||||
|
Please install an app that supports presenting map data.
|
||||||
|
</string>
|
||||||
|
|
||||||
|
<!-- Description -->
|
||||||
<string name="description_activity_type" translation_description="Activity type description.
|
<string name="description_activity_type" translation_description="Activity type description.
|
||||||
|
|
||||||
%1$s activity type. E.g., 'hiking'.">
|
%1$s activity type. E.g., 'hiking'.">
|
||||||
@@ -985,6 +989,7 @@ limitations under the License.
|
|||||||
what will be searched for.">
|
what will be searched for.">
|
||||||
Speak the name of a track or marker
|
Speak the name of a track or marker
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<!-- Sensor State -->
|
<!-- Sensor State -->
|
||||||
<string name="sensor_state_battery" translation_description="In the 'Sensor state' page, the label for the battery level on the bike
|
<string name="sensor_state_battery" translation_description="In the 'Sensor state' page, the label for the battery level on the bike
|
||||||
sensor. E.g., 'Battery level: 50 %'.">
|
sensor. E.g., 'Battery level: 50 %'.">
|
||||||
|
|||||||
Reference in New Issue
Block a user