处理在Android浏览器/ web视图的链接,直接启动应用程序 [英] Handle a link in the Android browser/webview to start directly an application

查看:89
本文介绍了处理在Android浏览器/ web视图的链接,直接启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的应用程序从一个链接打开, 通过以下的Make在Android浏览器链接启动我的应用程序?。 那么,它工作正常(大部分时间....这是我寻求帮助的原因)。

我的HTML链接是

< A HREF =的意图:#Intent,行动= com.mark.MY_ACTION;末>打开应用程序和LT ; / a取代;

我的意图过滤器的形式为

<意向滤光器>      <作用机器人:名称=com.mark.MY_ACTION/>      <类机器人:名称=android.intent.category.DEFAULT>      <类机器人:名称=android.intent.category.BROWSABLE> &所述; /意图滤光器>

到目前为止好(我希望)。它工作正常,从M-O-S-T的浏览器。

要测试上面我写了一个演示活动

最后的WebView的WebView =新的WebView(本); 的setContentView(web视图); webview.loadUrl(http://www.myhomepage.com/);

页面 http://www.myhomepage.com/ 有一些自定义链接/的HREF(包括 所述inent之一)。

pressing经常联系我打开这些链接的浏览器,但pressing我的特殊 链接(在INTNET一个)打开一个404页

  

找不到网页
  目的:#Intent,行动= com.mark.MY_ACTION末端
  可能暂时无法....

尽管戴安娜在<一提到href="http://stackoverflow.com/questions/3469908/make-a-link-in-the-android-browser-start-up-my-app/3472228">The上面的链接,

  

它们允许你直接发射到只有您的应用程序,而无需而不是去到浏览器或任何其他应用程序的选项给用户。

解决方案

将此code。在的Manifest.xml

&LT;意向滤光器&gt;     &lt;作用机器人:名称=android.intent.action.VIEW/&GT;     &LT;类机器人:名称=android.intent.category.DEFAULT/&GT;     &LT;类机器人:名称=android.intent.category.BROWSABLE/&GT;     &lt;数据         机器人:主机=www.parag-chauhan.com         机器人:路径=/测试         机器人:计划=HTTP/&GT; &所述; /意图滤光器&gt;

有关测试创建另一个项目并运行低于code

意向书我=新的意图(     Intent.ACTION_VIEW,Uri.parse(http://www.parag-chauhan.com/test) ); startActivity(ⅰ);

您还可以传递参数的链接。欲了解更多信息,请参见我的博客文章制作在Android浏览器链接启动我的应用程序?

I want my application to be opened from a link, by following the directions of Make a link in the Android browser start up my app?. Well, it works fine (most of the time.... this is the reason I am asking for help).

My html link is

<a href="intent:#Intent;action=com.mark.MY_ACTION;end">Open Application</a>

My intent filter is in the form

<intent-filter>
     <action android:name="com.mark.MY_ACTION"/>
     <category android:name="android.intent.category.DEFAULT">
     <category android:name="android.intent.category.BROWSABLE">
</intent-filter>

So far so good (I hope). It works fine from m-o-s-t of the browsers.

To test the above I wrote a demo activity

final WebView webview = new WebView(this); 
setContentView(webview); 
webview.loadUrl("http://www.myhomepage.com/"); 

The page http://www.myhomepage.com/ has some custom links/hrefs (including the inent one).

Pressing regular links opens me a browser with those links, but pressing my "special link" (the intnet one) opens a 404 page

Web page not available
intent:#Intent;action=com.mark.MY_ACTION;end
might be temporarily down....

While Diane mentioned in The above link,

They allow you to direct the launch to only your app without the user having the option of instead going to the browser or any other app.

解决方案

Add this code in Manifest.xml

<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="www.parag-chauhan.com"
        android:path="/test"
        android:scheme="http" />
</intent-filter>

For test create another project and run below code

Intent i = new Intent(
    Intent.ACTION_VIEW , Uri.parse("http://www.parag-chauhan.com/test")
);
startActivity(i);

You can also pass parameter in link. For more info, see my blog post Make a link in the Android browser start up my app?

这篇关于处理在Android浏览器/ web视图的链接,直接启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆