2017-08-28 165 views
1

我试图让网址打开应用程序,并有一些数据与此网址传递到应用程序,但它不起作用。在AndroidManifest.xml在Android上深层链接反应原生应用程序

我的活动标签:

<activity 
    android:name=".MainActivity" 
    android:label="@string/app_name" 
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize" 
    android:windowSoftInputMode="adjustResize" 
    android:launchMode="singleTask">       <-- added this 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.LAUNCHER" /> 
    </intent-filter> 
    <intent-filter> 
     <action android:name="fcm.ACTION.HELLO" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
    </intent-filter> 
    <intent-filter> 
     <action android:name="android.intent.action.VIEW" /> 
     <category android:name="android.intent.category.DEFAULT" /> 
     <category android:name="android.intent.category.BROWSABLE" /> 
     <data 
     android:scheme="conv" 
     android:host="convid"/> <-- so urls of the form 'conv://convid/ will open the app 
    </intent-filter> 
    </activity> 

我加入到入门级的应用程序:

componentDidMount() { 
    Linking.addEventListener('url', (e) => { 
     console.log("url", e); 
    }); 

    Linking.getInitialURL().then((url) => { 
     if (url) { 
     console.log('Initial url is: ' + url); 
     } 
    }) 
    } 

但是当我打开浏览器,进入conv://convid什么都没有记录和应用程序无法打开。

当然,我在浏览器之前打开了我的应用程序。

+0

您是否查看了[链接]上的React Native文档(https://facebook.github.io/react-native/docs/linking.html)? – alexdriedger

+0

@alexdriedger是的,我编辑了我的问题。 – shinzou

回答

1
  • 如果链接输入到浏览器的地址栏中,该应用程序将不会打开。它必须是一个web页面<a/>像标签:一些页面内

    <a href="http://example.com"></a>

链接。 (https://developer.chrome.com/multidevice/android/intents

由于您可能没有网页来放置标签,因此您可以使用adb命令进行测试。打开控制台,并写入以下行:

adb shell am start -W -a android.intent.action.VIEW -d "YOURHOST://YOURSCEME/" com.YOURAPPNAME 

例如,在你的情况应该是这样的(改变YOURAPPNAME与您的应用程序的名称):

adb shell am start -W -a android.intent.action.VIEW -d "convid://conv/" com.YOURAPPNAME 
  • 如果你是使用Windows和,如果它说adb命令未定义,则需要在SDK文件夹内运行platform-toolsfolder命令,例如:

    Android/Sdk/platform-tools/

+0

我把链接放在jsfiddle.net中,并从模​​拟器打开它,它工作。为什么他们没有在反应原生文档中提到这一点...... – shinzou

相关问题