Skip to content

Commit a1f7fcc

Browse files
committed
chore: first commit
1 parent 4684748 commit a1f7fcc

11 files changed

Lines changed: 14418 additions & 23 deletions

File tree

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# react-native-process-text-intent
22

3-
get text from android PROCESS_TEXT intent
3+
Get text from android `android.intent.action.PROCESS_TEXT` intent-filter
4+
5+
# Demo
6+
7+
<img src="media/demo.gif" width="40%" />
48

59
## Installation
610

@@ -11,11 +15,30 @@ npm install react-native-process-text-intent
1115
## Usage
1216

1317
```js
14-
import { multiply } from 'react-native-process-text-intent';
18+
import { getProcessTextIntent } from 'react-native-process-text-intent';
1519

1620
// ...
1721

18-
const result = await multiply(3, 7);
22+
getProcessTextIntent()
23+
.then((textResult) => {
24+
if (textResult) {
25+
console.log(textResult, 'ProcessedText'); // here will be your processed Text coming from android.intent.action.PROCESS_TEXT intent-filter
26+
}
27+
})
28+
.catch((error) => {
29+
console.log(error);
30+
});
31+
};
32+
```
33+
34+
first you need to add this `intent-filter` in `AndroidManifest.xml`
35+
36+
```xml
37+
<intent-filter>
38+
<action android:name="android.intent.action.PROCESS_TEXT" />
39+
<category android:name="android.intent.category.DEFAULT" />
40+
<data android:mimeType="text/plain" />
41+
</intent-filter>
1942
```
2043

2144
## Contributing

android/src/main/java/com/processtextintent/ProcessTextIntentModule.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.processtextintent;
22

3+
import android.app.Activity;
4+
import android.content.Intent;
5+
36
import androidx.annotation.NonNull;
47

58
import com.facebook.react.bridge.Promise;
@@ -23,10 +26,14 @@ public String getName() {
2326
}
2427

2528

26-
// Example method
27-
// See https://reactnative.dev/docs/native-modules-android
2829
@ReactMethod
29-
public void multiply(double a, double b, Promise promise) {
30-
promise.resolve(a * b);
30+
public void processedText(Promise promise) {
31+
try {
32+
Activity activity= getCurrentActivity();
33+
CharSequence text = activity.getIntent().getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
34+
promise.resolve(text);
35+
} catch (Exception ex) {
36+
promise.reject(ex);
37+
}
3138
}
3239
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
android:launchMode="singleTask"
1818
android:windowSoftInputMode="adjustResize"
1919
android:exported="true">
20+
<intent-filter>
21+
<action android:name="android.intent.action.PROCESS_TEXT" />
22+
<category android:name="android.intent.category.DEFAULT" />
23+
<data android:mimeType="text/plain" />
24+
</intent-filter>
2025
<intent-filter>
2126
<action android:name="android.intent.action.MAIN" />
2227
<category android:name="android.intent.category.LAUNCHER" />

0 commit comments

Comments
 (0)