如何使用特定于 url 的 React Native 打开应用程序 [英] How to open app with an url specific react native

查看:52
本文介绍了如何使用特定于 url 的 React Native 打开应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习本教程:

https://medium.com/react-native-training/deep-linking-your-react-native-app-d87c39a1ad5e

但是当我在浏览器中输入这个 url 时,我的应用程序没有运行:

but my app doesn't lunched when I type this url at browser:

peopleapp://people/0

我的manifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="*.*.*"
    xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:largeHeap="true"
      android:theme="@style/AppTheme"
      android:supportsRtl="false"
      android:screenOrientation="portrait"
      tools:replace="android:supportsRtl">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter android:label="filter_react_native">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="peopleapp" android:host="people" />
        </intent-filter>


      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />

      <service android:name="io.invertase.firebase.messaging.RNFirebaseMessagingService">
          <intent-filter>
          <action android:name="com.google.firebase.MESSAGING_EVENT" />
          </intent-filter>
    </service>
    <service android:name="io.invertase.firebase.messaging.RNFirebaseInstanceIdService">
        <intent-filter>
        <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
        </intent-filter>
    </service>


  <meta-data
    android:name="com.google.firebase.messaging.default_notification_channel_id"
    android:value="teamcide"/>


  <meta-data
     android:name="com.google.android.geo.API_KEY"
     android:value="AIzaSyDpiU78-****S6Lvllgqo"/>

    </application>

</manifest>

推荐答案

你可以使用下面的代码在 react native 中打开特定的 url

Hii you can use following code to open specific url in react native

const url = 'whatsapp://';
Linking.canOpenURL(url)
.then(supported => {
  if (!supported) {
    console.log('Can\'t handle url: ' + url);
  } else {
    return Linking.openURL(url);
  }
}).catch(err => console.error('An error occurred', err));

或者您也可以查看这个 url 了解更多信息

Or you can also check this url for more information

这篇关于如何使用特定于 url 的 React Native 打开应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆