Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/falcucci/react-native-activity-result
A simple React Native native module for invoking `Activity.startActivityForResults`, `Activity.setResults`, and `Activity.finish` to help with implementing app-to-app communication.
https://github.com/falcucci/react-native-activity-result
Last synced: about 2 months ago
JSON representation
A simple React Native native module for invoking `Activity.startActivityForResults`, `Activity.setResults`, and `Activity.finish` to help with implementing app-to-app communication.
- Host: GitHub
- URL: https://github.com/falcucci/react-native-activity-result
- Owner: falcucci
- License: mit
- Fork: true (rozele/react-native-activity-result)
- Created: 2018-05-02T23:02:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-22T17:27:16.000Z (almost 6 years ago)
- Last Synced: 2024-07-03T12:10:03.673Z (3 months ago)
- Language: Java
- Size: 12.7 KB
- Stars: 8
- Watchers: 0
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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-fork --save`
### Mostly automatic installation
`$ react-native link react-native-activity-result-fork`
### Manual installation
#### Android
1. 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 the `getPackages()` method
2. Append the following lines to `android/settings.gradle`:
```
include ':react-native-activity-result-fork'
project(':react-native-activity-result-fork').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-activity-result/android')
```
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
```
compile project(':react-native-activity-result-fork')
```## Usage
```javascript
import ActivityResult from 'react-native-activity-result-fork';// Check if an app is installed to handle an intent
const activity = await ActivityResult.resolveActivity('com.example.INTENT');
if (!activity) {
console.warn('Please install the othe app.');
} else {
console.log(`Activity will be handled by ${activity.package}`);
}// Start an activity for a result
let uniqueId = 0;
let args = /* ... */;
const response = await ActivityResult.startActivityForResult(++uniqueId, 'com.example.INTENT', args);
if (response.resultCode !== ActivityResult.OK) {
throw new Error('Invalid result from activity.');
} else {
console.log('Got the following response: ' + response.data);
}// Finish an activity with a result
ActivityResult.finish(ActivityResult.OK, 'com.Example.INTENT', args);
```