Skip to content

add on new intent override plugin for expo android #579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

f0wu5u
Copy link

@f0wu5u f0wu5u commented Sep 18, 2024

In reaction to this issue #558 and this closed PR #559.

This adds the;

import android.content.intent

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    setIntent(intent)
  }

by default if import android.content.intent is not already in MainActivity and if override fun onNewIntent(intent: Intent?) is not already implemented.

This ultimately resolves issue with expo android not opening deeplinks when app is in background

cc: @iway1

@f0wu5u f0wu5u force-pushed the patch/expo-android-on-new-intent-override branch from 2ada035 to 1a3ba77 Compare September 18, 2024 14:50
@erenkulaksiz
Copy link

why not merge?🚨🚨🚨🚨🚨🚨

@jp1987
Copy link

jp1987 commented Jan 27, 2025

Please merge this.

Co-authored-by: Jesper Paardekooper <j.paardekooper@rinkel.nl>

if (!nextContent.includes(intentImportString)){
const packageString = `${packageName}\n`
nextContent = nextContent.replace(packageString,`${packageString}\n${intentImportString}`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new line at the end of the import.

Suggested change
nextContent = nextContent.replace(packageString,`${packageString}\n${intentImportString}`)
nextContent = nextContent.replace(packageString,`${packageString}\n${intentImportString}\n`)

@saseungmin
Copy link

saseungmin commented Jun 10, 2025

I encountered the following error:

Task :app:compileDebugKotlin FAILED
e: file:///Users/saseungmin/workspace/essentory-app/android/app/src/main/java/com/essentory/app/MainActivity.kt:17:3 'onNewIntent' overrides nothing.
e: file:///Users/saseungmin/workspace/essentory-app/android/app/src/main/java/com/essentory/app/MainActivity.kt:18:23 Argument type mismatch: actual type is 'android.content.Intent?', but 'android.content.Intent' was expected.

Fixed by updating the code to:

import android.content.Intent

override fun onNewIntent(intent: Intent) {
  super.onNewIntent(intent)
  setIntent(intent)
}
  • Expo SDK 53, react-native v0.79.2 project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants