forked from alinz/react-native-share-extension
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathShareExModule.java
More file actions
71 lines (52 loc) · 2.08 KB
/
ShareExModule.java
File metadata and controls
71 lines (52 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.github.alinz.reactNativeShareExtension;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ActivityEventListener;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;
import javax.annotation.Nullable;
public class ShareExModule extends ReactContextBaseJavaModule implements ActivityEventListener {
public ShareExModule(ReactApplicationContext reactContext) {
super(reactContext);
reactContext.addActivityEventListener(this);
}
public String getName() {
return "ReactNativeShareExtension";
}
@ReactMethod
public void data(Promise promise) {
promise.resolve(processIntent());
}
protected WritableMap processIntent() {
Activity currentActivity = getCurrentActivity();
WritableMap map = Arguments.createMap();
Intent intent = currentActivity.getIntent();
String action = intent.getAction();
String type = intent.getType();
String value = "";
if (type == null) {
type = "";
}
//if you want to support more, just add more things here.
//at the moment we are only supporting browser URL
if (Intent.ACTION_SEND.equals(action) && "text/plain".equals(type)) {
value = intent.getStringExtra(Intent.EXTRA_TEXT);
}
map.putString("type", type);
map.putString("value", value);
return map;
}
@ReactMethod
public void close() {
Activity currentActivity = getCurrentActivity();
currentActivity.finish();
}
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) { }
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) { }
public void onNewIntent(Intent intent) { }
}