openUrl is not working in first attempt for mailto option in emulator in react native - react-native

I have tried to open gmail using linking.openUrl - mailto option. I can open gmail in my real device with first attempt.But In emulator its not open in first attempt and if I click same link second time it open gmail.
I couldn't understand what could be the cause.
Sample code:
Linking.canOpenURL(url)
.then(ok => {
if (ok) {
console.log(Linking.openURL(url));
return Linking.openURL(url);
} else {
console.warn("can't open mailto: iOS sim doesn't support it");
}
})
.catch(err => {
console.error(err);
});
Initially checking given url is valid or not. If valid try to open using openUrl concept

Related

react-native-biometrics - check if another faceid is added in ios

Lets say i setup FaceId on the phone. Then i registered for biometrics in the app. Everything works fine. But now when i add another FaceId, and when i try to login again, it should be able to detect that a new faceId has been added and it should give me an error or something. How can this be achieved with react-native-biometrics library. In android it can be detected if a new fingerprint is added but not when delete a fingerprint. but in ios cannot detect if the faceid is reset or a new one addded.
eg. code
const checkKeyExist = yield rnBiometrics.biometricKeysExist()
if (checkKeyExist.keysExist) {
const epochTimeSeconds = Math.round(new Date().getTime() / 1000).toString()
try {
const createSignature = yield rnBiometrics.createSignature({
promptMessage: 'Sign in',
payload: epochTimeSeconds
})
} catch (err) {
// Should catch that error here
}
}
any help would be much appreciated

How to open URL with scheme intent:// on react native

I have a react native mobile app with a webview. In the webview I added the facebook messenger chat plugin so my users can easily contact us if they need help.
if you ran the website through a mobile browser it works. It redirects you to the official messenger.
But when you ran it through react native webview somehow it says No activity found to handle Intent
here is my code on how i handle the opening of the intent
onShouldStartLoadWithRequest={(request) => {
let url = request.url
if(url.startsWith('intent:')){
Linking.openURL(url).catch(er => {
console.log(er)
alert("Failed to open URL")
});
return false
}else{
return true
}
}}
this will console log
[Error: Could not open URL
'intent://user/107571147455693/?intent_trigger=mme&nav=discover&source=customer_chat_plugin&source_id=1507329&metadata=%7B%22referer_uri%22%3A%22https%3A%5C%2F%5C%2Ffusiontechph.com%5C%2Ff9fe1863270a2%22%7D#Intent;scheme=fb-messenger;package=com.facebook.orca;end':
No Activity found to handle Intent { act=android.intent.action.VIEW
dat=intent://user/107571147455693/?intent_trigger=mme&nav=discover&source=customer_chat_plugin&source_id=1507329&metadata={"referer_uri":"https://fusiontechph.com/f9fe1863270a2"}
flg=0x10000000 }]
I have a workaround that worked for me. Facebook messenger provides a link to your facebook page message. So you can just open that link directly without using the intent scheme of facebook here is the final code
onShouldStartLoadWithRequest={(request) => {
let url = request.url
if(url.startsWith('intent:')){
Linking.openURL('https://m.me/mluc.jsites').catch(e=>{
console.log(e) })
return false
}else{
return true
}
}}

Can't connect to a device using react-native-bluetooth-classic

I am trying to send data from one android phone to another using "react-native-bluetooth-classic". I successfully run the example in the repo, but I am not able to connect to the paired devices. Sometimes, I can connect to a phone but the other can't connect back.
Is there any configuration I should to the phone's bluetooth?
Merged the pull request last night, should be able to connect from one device to another with the provided BluetoothClassicExample app using the Accept Connection button at the bottom of the device list.
async acceptConnections() {
console.log("App is accepting connections now...");
this.setState({ isAccepting: true });
try {
let connectedDevice = await RNBluetoothClassic.accept();
if (connectedDevice) { // Undefined if cancelled
this.setState({ connectedDevice, isAccepting: false });
}
} catch(error) {
console.log(error);
this.refs.toast.show(
`Unable to accept client connection`,
DURATION.LENGTH_SHORT
);
this.setSTate({ isAccepting: false });
}
}
This is only available on Android as from what I've seen, there are no ways to see the connection on IOS. I was able to connect my Android to my IOS using the example app, but without the Android MFi protocols, the data just gets sent into the IOS void.

Open Whatsapp from React Native app with Expo

Currently trying to open whatsapp from my React Native app with Expo. I have the code below:
let url = 'whatsapp://app';
Linking.openURL(url).then((data) => {
console.log('WhatsApp Opened');
}).catch((err) => {
console.log(err);
alert('Make sure Whatsapp installed on your device');
});
The error I get is this:
Error: Could not open URL 'whatsapp://app': No Activity found to handle Intent { act=android.intent.action.VIEW dat=whatsapp://app flg=0x10000000 }
However when I change the url to send, it opens whatsapp fine?
whatsapp://send?phone=3464478983
I am trying to only open whatsapp without a send param

Linking in react native can open just one app

UPDATE 1
I removed return from code and now links work on IOS.
But on android I can't open any app. Any idea?
I am trying to open different apps from my app.
return Linking.openURL(“twitter://“);
return Linking.openURL(“instagram://“);
But it doesn’t work. I configured IOS by documentation. On android doesn’t work too. While...
return Linking.openURL(“tripadvisor://“);
Work just fine.
Any idea why I can’t open other apps.
This is code that I am using (open app if installed or open store with it but sometimes even store doesn't open) what I did wrong:
let appUrl = "instagram://";
Linking.canOpenURL(appUrl).then(supported => {
if (!supported) {
Alert.alert("",
"",
[
{text: "go to store", onPress: this.openStorePress},
{text: "cancel", onPress: () => { }, style: 'cancel'},
],
{ cancelable: false }
);
} else {
return Linking.openURL(appUrl);
}
}).catch(err => {
console.error(err);
});
Your issue is related to the content of the url, twitter:// means nothing for the Android Twitter app, so it will not open.
For example, the following code should work:
Linking.openURL('twitter://timeline')
or
Linking.openURL('instagram://user?username=apple')
You have to find the rights url schemes (documentations are not very clear about it) that may be different between iOS and Android.
Twitter: How can I open a Twitter tweet using the native Twitter app on iOS?
Instagram: https://www.instagram.com/developer/mobile-sharing/iphone-hooks/ (all do not work on Android)
misc: https://pureoxygenlabs.com/10-app-url-schemes-for-marketers/
You have to find the rights URL schemes. Have look at my code
Instagram
Linking.openURL('instagram://user?username=apple')
.catch(() => {
Linking.openURL('https://www.instagram.com/apple');
})
Twitter
Linking.openURL('twitter://user?screen_name=apple')
.catch(() => {
Linking.openURL('https://www.twitter.com/apple');
})
Facebook
Linking.openURL('fb://page/PAGE_ID');
Linking.openURL('http://instagram.com/_u/USER_NAME');
Linking.openURL('http://instagram.com/_p/PICTURE');
Your code looks pretty solid, here's an example of how I open twitter in my app.
const twitterUrlScheme = `twitter://user?screen_name=${twitterUsername}`;
Linking.canOpenURL(twitterUrlScheme)
.then((supported) =>
Linking.openURL(
supported
? twitterUrlScheme
: `https://www.twitter.com/${twitterUsername}`
)
)
.catch((err) => console.error('An error occurred', err));
I think perhaps your issue might be the return Linking.openUrl, I'm not sure you need the return in that statement. Does it work if you remove the return? Otherwise, it might help to move your Alert outside of the then-block from canOpenUrl.
I have used only url and it's working both iOS and android
Linking.openURL('https://www.facebook.com/');
You haven't completed the " fot twitter and instagram, I don't know whether you made the same mistake in app too, if yes, fixing that might solve it.
Try to use a package like:
https://github.com/react-native-community/react-native-share
You can try to use only some of it's functions or look into the native code from there and create some bridge functions in the native code and then export them to be used in JS code.
Note: you will have to use real devices for the tests.