react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[android] Linking.getInitialURL() throws error

Open ggunti opened this issue 3 years ago • 7 comments

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

  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

ggunti avatar Aug 25 '22 13:08 ggunti

Hey, I am having the same issue, did you find any fix to this? Thanks

Yooooomi avatar Oct 14 '22 16:10 Yooooomi

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 avatar Oct 17 '22 12:10 Yooooomi

@Yooooomi We also use the same library, thank you for sharing your findings, we'll try it out and update in this thread 😄

professorkolik avatar Oct 17 '22 14:10 professorkolik

@Yooooomi can you post your work somewhere with demo app? I'm attempting to use that library but it is hanging on splash screen

frankcalise avatar Oct 17 '22 15:10 frankcalise

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 avatar Oct 17 '22 15:10 Yooooomi

@Yooooomi thanks I'll try that out

frankcalise avatar Oct 17 '22 16:10 frankcalise

@Yooooomi Thank you so much, that was the issue for us as well

UPD Unfortunately it still does happen

professorkolik avatar Oct 18 '22 10:10 professorkolik

Hello, I'm also facing the same, any solution so far?

dhayaljaswantgit avatar Mar 15 '23 13:03 dhayaljaswantgit

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.

github-actions[bot] avatar Dec 28 '23 05:12 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Jan 04 '24 05:01 github-actions[bot]