[android] Linking.getInitialURL() throws error
See original GitHub issueDescription
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® Core™ 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
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:7
Top GitHub Comments
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.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.