question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[android] Linking.getInitialURL() throws error

See original GitHub issue

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® 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

  1. Create a bare react-native project
  2. 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.

  1. Run the app on android

Snack, code example, screenshot, or link to a repository

https://snack.expo.dev/8OiPWgvkM

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

2reactions
Yooooomicommented, Oct 17, 2022

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.

1reaction
Yooooomicommented, Oct 17, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Linking.getInitialURL() is not being cleared after used for ...
Linking.getInitialURL() gives us the same Url when we come back to the same page again, to Overcome this we can do a simple...
Read more >
Linking · React Native
getInitialURL().then((url) => { if (url) { console.log('Initial url is: ' + ... for deep linking on Android, refer to Enabling Deep Links for...
Read more >
Linking - React Native Archive
getInitialURL().then(url) => { if (url) { console.log('Initial url is: ' + ... for deep linking on Android, refer Enabling Deep Links for App...
Read more >
Linking - Expo Documentation
Android Device, Android Emulator, iOS Device, iOS Simulator, Web ... Linking.getInitialURL(). Get the URL that was used to launch the app if it...
Read more >
Deep linking - React Navigation
This guide will describe how to configure your app to handle deep links on ... To configure the external linking in Android, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found