Intent to receive Google maps share actions

This commit is contained in:
vdv committed 2023-04-02 20:23:18 +02:00
1 parent 60ca62bf09
commit 20bb1387fc
2 files changed
+60 -1

No files matched your search

+54 -1
View File
@@ -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]);