2017-08-27 51 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

相关问题