首页 > 解决方案 > 如何将导出的 whatsapp 文档共享到 react-native 应用程序

问题描述

我是 React native 的新手,我想导出我的 whatsapp 聊天并将其分享到我的 react native 应用程序。

有两个软件包可以提供帮助:

https://www.npmjs.com/package/react-native-file-share-intent
https://github.com/meedan/react-native-share-menu

我尝试使用第二个包,因为如果我们使用 react-navigation,第一个包不起作用,所以我安装了第二个包,它工作得非常好,但是在我遇到两个问题之后:

  1. 如果我使用这个包,主屏幕图标没有创建,我不知道为什么图标没有在主屏幕中创建,而是放在共享缩进中
  2. 当我尝试从文件管理器共享文本文档时,反应本机应用程序图标被放置在共享缩进中,并且它运行良好。但是我在什么应用程序中尝试过的同样的事情意味着它不起作用。我认为当我从 WhatsApp 导出时,它最初是作为临时文件创建的。这就是为什么我的应用程序没有显示在该共享缩进中的原因。

我在 GitHub 存储库中推送了我的代码,存储库的链接是: https ://github.com/BalaRajendran/sharemenu-reactnative

App.js - https://github.com/BalaRajendran/sharemenu-reactnative/blob/master/App.js

 export default class App extends Component {
      constructor(props) {
        super(props);
        this.state = {
          fileUrl: null,
        };
      }

      componentDidMount() {
        if (RNFileShareIntent) {
          RNFileShareIntent.getFilepath((url) => {
            this.setState({ fileUrl: url });
          })
        }
      }

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.sharemenu">
    <uses-permission android:name="android.permission.INTERNET" />
    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
      android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize"  
        >
        <intent-filter>
            ///changed code according to react-native-share-menu
            <action android:name="android.intent.action.PICK"/>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/*" />
            <data android:mimeType="image/*" /> 
            <data android:mimeType="file/*" /> 
            <data android:mimeType="application/*" />
             //
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

所以你能帮我解决我的问题吗?

标签: androidreact-nativereact-native-android

解决方案


推荐阅读