java - 处理 Android 浏览器/webview 中的链接以直接启动应用程序

标签 java android

我希望通过链接打开我的应用程序, 按照 Make a link in the Android browser start up my app? 的指示进行操作. 好吧,它工作正常(大部分时间......这就是我寻求帮助的原因)。

我的html链接是

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

我的 Intent 过滤器的形式是

<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>

到目前为止一切顺利(我希望如此)。它在 m-o-s-t 浏览器中运行良好。

为了测试上面我写了一个演示 Activity

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

http://www.myhomepage.com/ 页面有一些自定义链接/href(包括 Intent 之一)。

按常规链接会打开带有这些链接的浏览器,但按我的“特殊链接” 链接”(内部网)打开一个 404 页面

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

虽然黛安在 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.

最佳答案

您的 Intent Filter 与 Diana 提到的有些相同

<activity android:name=".AntonWorld"
      android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <intent-filter>
        <data android:scheme="anton" />
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.BROWSABLE" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

所以你的应该是这样的:

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

没有测试是否需要 android.intent.category.VIEW。让我知道它是否有效。

关于java - 处理 Android 浏览器/webview 中的链接以直接启动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7570253/

相关文章:

java.exe 进程使用了​​更多内存并且没有释放它

php - 应用程序发明家 2 POST

java - 如何使用反射循环子类中的字段

android - 了解 keystore 、证书和别名

android - 为什么我得到 java.lang.IllegalArgumentException : background can not be translucent: #0 when using MediaRouteButton?

android - 如何从android中的 Activity 接收数据?

java - 我需要使用 Java 创建搜索引擎的帮助

java - 我的复选框列表未填充相应的值

java - List 的类属性类型,不可由访问器修改

java - 自定义 Android 对话框方向更改