2017-08-28 114 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