Skip to content

Commit ec5d56e

Browse files
committed
added intent without Component
1 parent 7d10865 commit ec5d56e

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

android/src/main/java/com/poberwong/launcher/IntentLauncherModule.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.facebook.react.bridge.*;
1111

1212
import java.io.Console;
13+
import java.util.Set;
14+
import java.util.Iterator;
1315

1416
/**
1517
* Created by poberwong on 16/6/30.
@@ -56,7 +58,27 @@ public void startActivity(ReadableMap params, final Promise promise){
5658
}
5759
getReactApplicationContext().startActivityForResult(intent, 12, null); // 暂时使用当前应用的任务栈
5860
} catch (Exception e) {
59-
promise.reject("Could not open intent");
61+
promise.reject("ERROR", "Could not open intent");
62+
}
63+
}
64+
65+
@ReactMethod
66+
public void startActivityOnlyIntent (ReadableMap params, final Promise promise) {
67+
this.promise = promise;
68+
try {
69+
Intent intent = new Intent(params.getString(ATTR_DATA));
70+
if (params.hasKey(TAG_EXTRA)) {
71+
intent.putExtras(Arguments.toBundle(params.getMap(TAG_EXTRA)));
72+
}
73+
if (params.hasKey(ATTR_FLAGS)) {
74+
intent.addFlags(params.getInt(ATTR_FLAGS));
75+
}
76+
if (params.hasKey(ATTR_CATEGORY)) {
77+
intent.addCategory(params.getString(ATTR_CATEGORY));
78+
}
79+
getReactApplicationContext().startActivityForResult(intent, 12, null); // 暂时使用当前应用的任务栈
80+
} catch (Exception e) {
81+
promise.reject("ERROR", "Could not open intent");
6082
}
6183
}
6284

@@ -68,10 +90,26 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
6890
if (requestCode != 12) {
6991
return;
7092
}
71-
WritableMap params;
93+
WritableMap params = Arguments.createMap();
7294
Bundle extras = data.getExtras();
7395

74-
params = Arguments.fromBundle(extras);
96+
Set<String> keys = extras.keySet();
97+
Iterator<String> it = keys.iterator();
98+
Log.e("LGC","Dumping Intent start");
99+
while (it.hasNext()) {
100+
String key = it.next();
101+
if (extras.get(key) instanceof String) {
102+
params.putString(key, (String) extras.get(key));
103+
}
104+
105+
if (extras.get(key) instanceof Integer) {
106+
params.putInt(key, (Integer) extras.get(key));
107+
}
108+
109+
Log.e("LGC", "[" + key + "=" + extras.get(key) + "]");
110+
}
111+
112+
// params = Arguments.fromBundle(extras);
75113

76114
this.promise.resolve(params);
77115

0 commit comments

Comments
 (0)