Skip to content
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

Linking.sendIntent startActivity from outside of an Activity context error #28934

Closed
Aure77 opened this issue May 20, 2020 · 8 comments
Closed
Labels
API: Linking Platform: Android Android applications. Resolution: PR Submitted A pull request with a fix has been provided. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@Aure77
Copy link

Aure77 commented May 20, 2020

Description

I am trying to open security settings on android using Linking module :
Linking.sendIntent("android.settings.SECURITY_SETTINGS");

This result to this red box error:

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

React Native version:

React Native : 0.61.5

System:
OS: macOS 10.15.4
CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
Memory: 26.83 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6392135
Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild

Steps To Reproduce

  1. Call Linking.sendIntent("android.settings.SECURITY_SETTINGS"); in Android (9 in my test)

Expected Results

Security settings should open without error.

Suggestion

Add FLAG_ACTIVITY_NEW_TASK flag by default on indent or add ability on sendIntent to add flags.

@Aure77 Aure77 changed the title Linking.sendIntent startActivity from outside of an Activity context Linking.sendIntent startActivity from outside of an Activity context error May 20, 2020
@Aure77
Copy link
Author

Aure77 commented May 20, 2020

Another possible fix is to use getCurrentActivity() instead of getReactApplicationContext() here https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java#L238

@krizzu
Copy link
Contributor

krizzu commented May 28, 2020

Going to work on that. I'm going to the same thing as it's in openURL:

https://github.com/facebook/react-native/blob/master/ReactAndroid/src/main/java/com/facebook/react/modules/intent/IntentModule.java#L97-L101

@safaiyeh safaiyeh added Platform: Android Android applications. Resolution: PR Submitted A pull request with a fix has been provided. and removed Needs: Triage 🔍 labels Aug 15, 2020
@chge
Copy link

chge commented Jul 19, 2021

The same error if you try to use other system activities like a dialog asking the user to enable Bluetooth:

Linking.sendIntent('android.bluetooth.adapter.action.REQUEST_ENABLE');

facebook-github-bot pushed a commit that referenced this issue Sep 13, 2021
Summary:
Addresses #28934

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - When sending OS intents, always set "FLAG_ACTIVITY_NEW_TASK" flag (required by OS).

Pull Request resolved: #29000

Test Plan:
1. Open RNTester on Android
2. Go to Linking section
3. Try opening "POWER_USAGE_SUMMARY" intent
4. App should open settings, instead of crashing

Reviewed By: cortinico

Differential Revision: D30876645

Pulled By: lunaleaps

fbshipit-source-id: e427bfeadf9fb1ae38bf05bfeafd88e6776d71de
@ansarikhurshid786
Copy link

I am also facing same issue.

@krizzu
Copy link
Contributor

krizzu commented Nov 22, 2021

This is now pulled into FB repo
#29000

@acrabb
Copy link

acrabb commented Dec 15, 2021

Any update on this issue? I just ran into the same when linking to android's WiFi settings:

Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?

Looks like it was merged #29000? In what release will it go out in?

@github-actions
Copy link

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 github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 30, 2023
@github-actions
Copy link

github-actions bot commented May 7, 2023

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

@github-actions github-actions bot closed this as completed May 7, 2023
zhxlp pushed a commit to zhxlp/react-native that referenced this issue Aug 1, 2023
Summary:
Addresses facebook#28934

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://github.com/facebook/react-native/wiki/Changelog
-->

[Android] [Fixed] - When sending OS intents, always set "FLAG_ACTIVITY_NEW_TASK" flag (required by OS).

Pull Request resolved: facebook#29000

Test Plan:
1. Open RNTester on Android
2. Go to Linking section
3. Try opening "POWER_USAGE_SUMMARY" intent
4. App should open settings, instead of crashing

Reviewed By: cortinico

Differential Revision: D30876645

Pulled By: lunaleaps

fbshipit-source-id: e427bfeadf9fb1ae38bf05bfeafd88e6776d71de
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Linking Platform: Android Android applications. Resolution: PR Submitted A pull request with a fix has been provided. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

7 participants