[android] Linking.getInitialURL() throws error
Description
On android when trying to call Linking.getInitialURL() I always get [Error: Could not get the initial URL : Attempt to invoke virtual method 'java.lang.String android.content.Intent.getAction()' on a null object reference] error on android. On iOS it works.
The code:
import { Linking } from 'react-native';
try {
const res = await Linking.getInitialURL();
console.log(res);
} catch (e) {
console.log(e);
}
I mention that I added the following intent-filter to AndroidManifest.xml:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="myapp" />
</intent-filter>
Version
0.68.2
Output of npx react-native info
System: OS: macOS 12.3.1 CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz Memory: 413.03 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 16.15.0 - /usr/local/bin/node Yarn: 1.22.18 - /usr/local/bin/yarn npm: 8.5.5 - /usr/local/bin/npm Watchman: Not Found Managers: CocoaPods: 1.11.3 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8193401 Xcode: 13.3.1/13E500a - /usr/bin/xcodebuild Languages: Java: 11.0.2 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.68.2 => 0.68.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
- Create a bare react-native project
- Try to run:
import { Linking } from 'react-native';
try {
const res = await Linking.getInitialURL();
console.log(res);
} catch (e) {
console.log(e);
}
for example inside useEffect hook.
- Run the app on android
Snack, code example, screenshot, or link to a repository
https://snack.expo.dev/8OiPWgvkM
Hey, I am having the same issue, did you find any fix to this? Thanks
I managed to fix the issue. I was using the https://github.com/ajith-ab/react-native-receive-sharing-intent library. I fixed it using this comment, which was setting the intent to null. Hope it helps somebody.
@Yooooomi We also use the same library, thank you for sharing your findings, we'll try it out and update in this thread 😄
@Yooooomi can you post your work somewhere with demo app? I'm attempting to use that library but it is hanging on splash screen
This is the version we use: https://github.com/kraaft-co/react-native-receive-sharing-intent. Application stays on splash screen if I have hermes disabled.
@Yooooomi thanks I'll try that out
@Yooooomi Thank you so much, that was the issue for us as well
UPD Unfortunately it still does happen
Hello, I'm also facing the same, any solution so far?
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.