[英]How to send an intent to a specific app from react-native
我正在开发一个 react-native 移动应用程序,我想发送一个意图(地理:...)专门到谷歌 map 应用程序。 在本机示例中,他们使用 Intent.setPackage() function,但我找不到适用于 react-native 的类似解决方案。
这是我的代码,目前允许用户在可能的应用程序之间进行选择。 我希望只有谷歌地图应用程序管理意图。
<Text
style={{ textDecorationLine: 'underline', color: PURPLE }}
onPress={async () => {
const scheme = Platform.select({ ios: 'maps:0,0?q=', android: 'geo:0,0?q=' });
const latLng = `${item.latitude},${item.longitude}`;
const label = item.address;
const url = Platform.select({
ios: `${scheme}${label}@${latLng}`,
android: `${scheme}${latLng}(${label})`
});
const supported = await Linking.canOpenURL(url);
if (supported) {
await Linking.openURL(url);
} else {
Alert.alert(`Don't know how to open current address`);
console.log('error opening link', url);
}
}
}
>
{context.translations.GO_TO_MAPS}
</Text>
感谢您的帮助
我不确定这是否对您有帮助,但我用它在谷歌中打开地址
if(Platform.OS === 'ios'){
Linking.openURL(`maps://app?saddr=${latitude}+${longitude}&daddr=${parseFloat(latitude)}+${parseFloat(longitude)}`)
} else{
Linking.openURL(`google.navigation:q=${parseFloat(latitude)}+${parseFloat(longitude)}`)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.