React native 如何在react原生应用程序中处理发送意图(共享菜单项)?

React native 如何在react原生应用程序中处理发送意图(共享菜单项)?,react-native,React Native,我已经成功地将iOS应用程序配置为处理音频文档类型(而不是深度链接!),因此我可以使用共享对话框在我的应用程序中打开音频文件,这很好 我已经成功地在AndroidManifest.xml中配置了安卓intent filter,以同样的方式处理音频文件,安卓系统也能很好地识别这一点,当我在音频文件上使用共享菜单时,我会看到我的应用程序。然而,链接组件的Android实现似乎忽略了发送意图操作,而只关心查看意图操作,正如我在意图模块上看到的那样。java:55: if (Intent.ACT

我已经成功地将iOS应用程序配置为处理音频文档类型(而不是深度链接!),因此我可以使用共享对话框在我的应用程序中打开音频文件,这很好

我已经成功地在
AndroidManifest.xml
中配置了安卓
intent filter
,以同样的方式处理音频文件,安卓系统也能很好地识别这一点,当我在音频文件上使用共享菜单时,我会看到我的应用程序。然而,
链接
组件的Android实现似乎忽略了
发送
意图操作,而只关心
查看
意图操作,正如我在
意图模块上看到的那样。java:55

    if (Intent.ACTION_VIEW.equals(action) && uri != null) {
      initialURL = uri.toString();
    }
我试图在我的
MainActivity.java
中修补intent,使其返回与
视图
操作相同的uri,但这总是在运行时产生错误

@Override
public Intent getIntent() {
    Intent origIntent = super.getIntent();
    if (origIntent != null && Intent.ACTION_SEND.equals(origIntent.getAction())) {
        return new Intent(Intent.ACTION_VIEW, origIntent.getData());
    }
    return origIntent;
}
但是,我总是收到一个错误,指示
getData
为空


我看到了,但是拥有一个共享扩展对我来说太过分了。

我发现Intent可能包含名为
ClipData
的附加信息,它也可以包含
Uri
。我的运气是我正好有一个
Uri
(我想如果我同时共享多个音频文件,它可能包含多个
Uri
对象。所以这个代码起作用了,我现在可以共享文件来响应本地应用程序

@Override
public Intent getIntent() {
    Intent origIntent = super.getIntent();
    if (origIntent != null && Intent.ACTION_SEND.equals(origIntent.getAction())) {
        return new Intent(Intent.ACTION_VIEW, this.uriFromClipData(origIntent.getClipData()));
    }
    return origIntent;
}

private Uri uriFromClipData(ClipData clip) {
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).getUri();
    }
    return null;
}

我发现Intent可能包含名为
ClipData
的附加信息,这些信息也可以包含
Uri
。我的运气是我正好有一个
Uri
(如果我一次共享多个音频文件,我想它可能包含多个
Uri
对象。所以这段代码起作用了,我现在可以共享文件来响应本机应用程序。)

@Override
public Intent getIntent() {
    Intent origIntent = super.getIntent();
    if (origIntent != null && Intent.ACTION_SEND.equals(origIntent.getAction())) {
        return new Intent(Intent.ACTION_VIEW, this.uriFromClipData(origIntent.getClipData()));
    }
    return origIntent;
}

private Uri uriFromClipData(ClipData clip) {
    if (clip != null && clip.getItemCount() > 0) {
        return clip.getItemAt(0).getUri();
    }
    return null;
}