react-native-activity-result
A simple React Native native module for invoking Activity.startActivityForResult
, Activity.setResult
, and Activity.finish
to help with implementing app-to-app communication.
Getting started
$ npm install react-native-activity-result --save
Mostly automatic installation
$ react-native link react-native-activity-result
Manual installation
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.microsoft.ActivityResultPackage;
to the imports at the top of the file - Add
new ActivityResultPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-activity-result' project(':react-native-activity-result').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-activity-result/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-activity-result')
Usage
; // Check if an app is installed to handle an intentconst activity = await ActivityResult;if !activity console; else console; // Start an activity for a resultlet uniqueId = 0;let args = /* ... */;const response = await ActivityResult;if responseresultCode !== ActivityResultOK throw 'Invalid result from activity.'; else console; // Finish an activity with a resultActivityResult;