2017-02-13 77 views
1

我嘗試在當前打開的應用程序中使用branch.io鏈接打開新活動。 以下代碼有效。這裏的問題是瀏覽器打開,這就是新的活動。在同一個應用程序中打開branch.io鏈接

Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://sample.test-app.link/foo")); 
startActivity(actionIntent); 

我知道瀏覽器訪問branch.io的網站,獲取數據,並呼籲像intent://....一個其他鏈接。我正在尋找一種方法從網絡鏈接(https)獲取意向鏈接(intent://)。

謝謝!

回答

1

解決方法是啓用App links並在鏈接設置中添加SHA256指紋。

在你的應用程序中,你應該設置一個新的intent過濾器來獲取http請求。

<intent-filter android:autoVerify="true"> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> 
    <data android:scheme="https" android:host="xxxx.test-app.link" /> 
</intent-filter> 

現在您的應用程序接收並處理鏈接,瀏覽器將無法打開。

步驟描述爲in the docs

0

我認爲您可以通過以下步驟實現它:

在manifest文件中下活動的意圖過濾器放:

<data android:host="example.com" android:scheme="http" ></data> 

現在,您可點擊的鏈接應該是這樣的:

http://example.com/tutor/

在活動中,您可以對代碼做出任何基於URL的條件

Uri data = getIntent().getData(); 
    if(data!=null) { 
     List<String> params = data.getPathSegments(); 
     String first = params.get(0); // "status" 
     String second = params.get(1); 
    } 
+0

感謝您的幫助!你是對的,這應該可行,但我需要[branch.io](https://branch.io/)的一些解決方案。我現在已經找到了解決方案;-) – Fabi755

+0

很高興知道... :) – Khushvinder

1

Branch SDK的設計不便於從應用程序自己的webview中路由迴應用程序。這就是說,這聽起來像你已經得到了一些工作,這是太棒了。

關於抓取從分支鏈接創建的意圖字符串的最簡單方法:在安裝了應用程序的設備上,將分支鏈接粘貼到Chrome地址欄並按回車鍵。意圖字符串將出現在地址欄中以及出現在生成的網頁上的錯誤中。

以這種方式檢索意圖字符串的工作原理是因爲Chrome不支持通過在地址欄中輸入意向字符串來打開應用程序。

相關問題