From 20bb1387fc987b00e2f45213d15ebcf727906240 Mon Sep 17 00:00:00 2001 From: Eric van der Vlist Date: Sun, 2 Apr 2023 20:23:18 +0200 Subject: [PATCH] Intent to receive Google maps share actions --- AndroidManifest.xml | 6 +++++ src/components/map/Map.tsx | 55 +++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 85ad507..d2c2a10 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -51,6 +51,12 @@ + + + + + + diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index 5d05d6b..bf5cc08 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -116,7 +116,60 @@ const Map: Component = () => { location.hash = url.hash; location.pathname = url.pathname; } - } else if (intent.action === 'android.intent.action.SEND') { + } else if ( + intent.action === 'android.intent.action.SEND' && + !!intent.extras['android.intent.extra.TEXT'] + ) { + /* + + Intent from gmaps (example): + + { + "clipItems": [ + { + "text": "https://www.google.fr/maps/place/Th%C3%A9%C3%A2tre+Campoamor,+C.+Pelayo,+33003+Oviedo,+Asturias/@43.3622041,-5.8485043,17z/data=!4m6!3m5!1s0xd368cfacd5f4783:0x8629a4fbbc3232b5!8m2!3d43.3628346!4d-5.8479215!16s%2Fg%2F121d1flv" + } + ], + "type": "text/plain", + "extras": { + "android.intent.extra.SUBJECT": "", + "android.intent.extra.TEXT": "https://www.google.fr/maps/place/Th%C3%A9%C3%A2tre+Campoamor,+C.+Pelayo,+33003+Oviedo,+Asturias/@43.3622041,-5.8485043,17z/data=!4m6!3m5!1s0xd368cfacd5f4783:0x8629a4fbbc3232b5!8m2!3d43.3628346!4d-5.8479215!16s%2Fg%2F121d1flv" + }, + "action": "android.intent.action.SEND", + "flags": 272629761, + "component": "ComponentInfo{com.dyomedea.dyomedea/com.dyomedea.dyomedea.MainActivity}" +} + + or + + { + "clipItems": [ + { + "text": "https://www.google.fr/maps/place/C.+San+Francisco,+1,+33003+Oviedo,+Asturias/@43.3629409,-5.8458296,16z/data=!4m6!3m5!1s0xd368ce5636451f5:0x23dd7ba12d269d1b!8m2!3d43.3617786!4d-5.8464287!16s%2Fg%2F11bw44f29g" + } + ], + "type": "text/plain", + "extras": { + "android.intent.extra.SUBJECT": "", + "android.intent.extra.TEXT": "https://www.google.fr/maps/place/C.+San+Francisco,+1,+33003+Oviedo,+Asturias/@43.3629409,-5.8458296,16z/data=!4m6!3m5!1s0xd368ce5636451f5:0x23dd7ba12d269d1b!8m2!3d43.3617786!4d-5.8464287!16s%2Fg%2F11bw44f29g" + }, + "action": "android.intent.action.SEND", + "flags": 272629761, + "component": "ComponentInfo{com.dyomedea.dyomedea/com.dyomedea.dyomedea.MainActivity}" +} + + */ + + const matches = intent.extras['android.intent.extra.TEXT'].match( + /^https:\/\/www\.google\..+\/maps\/place\/(.+\/)?@(-?[0-9.]+),(-?[0-9.]+),[0-9]+z\/.*$/ + ); + if (matches) { + findLocation(navigate, [matches[3], matches[2]]); + } + } else if ( + intent.action === 'android.intent.action.SEND' && + !!intent.extras['android.intent.extra.STREAM'] + ) { const uri = intent.extras['android.intent.extra.STREAM']; // intent.type is 'image/*' for gallery share importUrls([uri]);