【发布时间】:2018-12-03 03:58:10
【问题描述】:
目前,以下代码确实成功获取了正在共享到应用程序的文本,但我无法找出如何将此事件发送到 Javascript 端。我尝试创建一个新的NavigationReactGateway,但我的应用程序崩溃了。我是 Java 新手,所以我什至不知道我是否做得对。
public class MainActivity extends SplashActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
protected String getMainComponentName() {
return "MyApplication";
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
handleSendText(intent);
}
}
}
void handleSendText(Intent intent) {
String sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
if (sharedText != null) {
// Send event to Javascript as "share" event
}
}
}
将此事件发送到 Javascript 的正确方法是什么?
该应用程序有react-native-navigation 并且有很多对事件发射器的引用,我只是不确定如何获取反应上下文来发射事件。如果这有任何意义。
【问题讨论】:
标签: java android react-native android-intent react-native-navigation