2017-08-27 110 views
0

我想在用戶單擊某個url時打開我的Activity。 我創建intent-filter這樣:在Chrome瀏覽器中從URL打開活動

 <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="http" 
       android:host="mysite.com" 
       android:pathPrefix="/prefix/" /> 
     </intent-filter> 

當我打開url從我收到的短信或指出它工作正常(我的活動打開),但是當我點擊該url從Chrome瀏覽器重定向我到基於Web現場。 我聽說chrome 23+存在問題,但我無法創建任何url,可能會將我重定向到我的activity,從chrome

我在做什麼錯了?

回答

1

我的應用程序之一,我使用如下所述(請用您的值替換主機,pathPrefix和端口)。在我的情況下,我爲dev,qa和production使用不同的主機,端口和pathPrefix。這就是爲什麼我添加意圖過濾器中的所有場景。它爲我工作很好。你能不能請這樣試試。

<activity 
     android:name=".SampleActivity" 
     android:label="@string/sample" 
     android:screenOrientation="portrait"> 
     <intent-filter> 
      <action android:name="android.intent.action.VIEW" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
      <category android:name="android.intent.category.BROWSABLE"/> 

      <!--Dev--> 
      <data 
       android:host="dev.mysite.com" 
       android:pathPrefix="/your path/" 
       android:port="4000" 
       android:scheme="http" /> 
      <data 
       android:host="mysite.com" 
       android:path="/your path/" 
       android:port="4000" 
       android:scheme="https" /> 

      <!--Qa--> 
      <data 
       android:host="qa.mysite.com" 
       android:pathPrefix="/your path/" 
       android:port="8000" 
       android:scheme="http" /> 
      <data 
       android:host="qa.mysite.com" 
       android:path="/your path/" 
       android:port="8000" 
       android:scheme="https" /> 

      <!--Production--> 
      <data 
       android:host="mysite.com" 
       android:pathPrefix="/your path/" 
       android:scheme="http" /> 
      <data 
       android:host="mysite.com" 
       android:path="/your path/" 
       android:scheme="https" />   
     </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"/> 
     </intent-filter> 
    </activity> 
+0

而你的網址從chrome運行應用程序?是否有一些服務器設置? – Rainmaker

+0

是的,我的應用程序將啓動並打開「SampleActivity」時,URL在任何瀏覽器中加載intent-filter中的數據匹配。服務器端沒有設置。 – prakash

+0

您使用的Android版本是什麼?是否有必要指定一個端口?我嘗試使用端口80,但沒有它,但沒有成功 – Rainmaker

相關問題