2014-03-19 115 views
1

我见过一些网站,如果他们有我的手机上安装的应用程序,如果我加载网站,我可以选择打开那里的应用程序。这是如何实现的,因为我想把它放到我的应用程序中。从铬启动我的应用程序

回答

1

他们在他们的清单注册一个接收器,像这样

<intent-filter> 
      <data android:scheme="" android:host="" android:path=""/> 
      <action android:name="android.intent.action.VIEW"/> 
      <category android:name="android.intent.category.BROWSABLE"/> 
      <category android:name="android.intent.category.DEFAULT"/> 
</intent-filter> 

其中scheme可以是http,host可以是网站和path可以是文件夹或东西

例如:

<intent-filter> 
      <data android:scheme="http" android:host="site.something" android:path="aPath"/> 
      <action android:name="android.intent.action.VIEW"/> 
      <category android:name="android.intent.category.BROWSABLE"/> 
      <category android:name="android.intent.category.DEFAULT"/> 
</intent-filter> 

会在您前往网站时触发http://site.something/aPath

你需要这段代码添加到当请求

+0

谢谢,所以'/ news'可以加载'NewsActivity','/ contact'可以加载'ContactActivity'我只需要一个单独的intent过滤器来加载我想要加载的每个URL? –

+0

是的,这绝对有可能。你用'/ news'意图过滤器和'ContactActivity'用'/ contact'意图过滤器声明一个'NewsActivity' – 0xDEADC0DE

+0

刚刚添加了这段代码,它并没有给我选择器,但它也不是第一个站点我注意到这一点。是否有可能重置Chrome来给​​我选择器,你知道吗? –

0

在网页上有一个脚本,它检测OS平台并显示一个弹出窗口来打开Goog​​le Play。 在应用程序中,您必须注册IntentFilter(在清单中),这会导致您的网页的URL拦截,因此,当您点击某个链接时,系统会询问您是否喜欢用应用程序或浏览器打开它。

1

网址,您可以通过使您的活动可浏览的,你需要添加下面的代码在你的menifest文件这样做是应当打开的活动

<activity 
      android:name=".YourActivityName" 
      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" /> 

       <data 
        android:host="host.com" 
        android:scheme="http" /> 
      </intent-filter> 

     </activity> 

只要包含http://host.com/的任何链接都会被点击,那么android会显示您的应用程序作为可打开此链接的选项之一。而已。

相关问题