2017-07-11 63 views
0

我正在開發的應用程序有一個下載鏈接,它通過點擊它在移動瀏覽器中打開,但我希望它在我的應用程序的webView中打開。我的應用程序不是Web應用程序我只想在webview中打開應用程序鏈接。我的網站上有數百個應用程序。我從wp api獲取應用程序,就像playstore一樣,用戶可以從我的應用程序下載應用程序。我嘗試了不同的解決方案,但沒有成功。 SS附加清楚我的問題。需要幫忙!!所有指定意圖過濾器的從WebView中的應用程序打開鏈接android

Here is the screenShot attached.

回答

0

首先要在應用

<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="https"/> 
     <data android:scheme="http"/> 
     <data android:host="pollux.androidapksfree.com"/> 
     <data android:pathPrefix="/hdata"/> 

    </intent-filter> 

打開鏈接,然後處理,並傳遞到的WebView在你的發射活動。

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     //check that link is not null 
     //or that you opened app from deep link 
     if (getIntent() != null) { 
      Uri intentUri = getIntent().getData(); //get link 
      webView = (WebView) findViewById(R.id.webView); 
      webView.getSettings().setJavaScriptEnabled(true); 
      webView.loadUrl(intentUri.toString()); //open it in webView 
     } 
    } 
+0

非常感謝您的回答,但它崩潰並顯示此運行時異常。 java.lang.NullPointerException:嘗試在null對象引用 –

+0

@ShahrozJavaid上調用虛擬方法'java.lang.String android.net.Uri.toString()'可能您還需要檢查getIntent()。getData()! = null。如果可能的話也顯示你的鏈接。 – DEADMC

+0

我現在做了一些改變,當我點擊它要求打開瀏覽器或我的應用程序的鏈接時。當我選擇我的應用程序時,它只顯示空白頁面而沒有發生任何操作。 –

0

在點擊該鏈接,Android操作系統將創建一個與該鏈接爲URL的意圖和搜索應用程序,可以處理intent.Since移動瀏覽器可以處理那些「HTTP://」意圖,其目的是扔到手機瀏覽器,並在那裏打開鏈接。 如果你想在你的webView中打開它,你必須聲明你的活動可以處理這些意圖,並且必須讓你的活動默認來處理這些意圖。

它可以通過以下鏈接

https://developer.android.com/training/app-indexing/deep-linking.html

請注意,如果你這樣做,則這些域的任何鏈接點擊任何地方將只與您的應用程序,因爲它是由默認打開

+0

謝謝親愛的。你解釋得很好,我明白了整個問題。試圖解決它。 –

相關問題