从网页打开安卓应用程序

31

我知道如果要在网页中的链接内打开安卓应用,我们需要在 AndroidManifest.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:scheme="my_scheme" android:host="my_host" />
        </intent-filter>
问题在于我以以下方式编写了它:
        <intent-filter>
            <action android:name="my_action"/>
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="my_scheme" android:host="my_host" />
        </intent-filter>

我没有添加 android.intent.action.VIEW,而是添加了自己创建的操作。由于版本已经发布,我无法更改。

问题是,

是否有一种方法可以从 JavaScript 或简单的 HTML 页面运行应用程序,通过在页面中定义特定的操作?

谢谢,

Paz.


已解决:

感谢 David,我找到了一个解决方案:

<a href="intent://my_host#Intent;scheme=my_scheme;action=my_action;end">Link to my stuff</a> 

为什么你不能发布一个更新来修复它呢? - David Wasser
这肯定能解决问题,但由于公司的限制,我无法发布新版本。 - Paz
4个回答

35

谢谢David,你说的intent:#Intent是什么意思?它不应该是my_scheme://my_host吗?还是我应该按照原样写(intent:#Intent)? - Paz
1
嗨,David,由于我正在使用主机和方案,这是完整的解决方案:<a href="intent://my_host#Intent;scheme=my_scheme;action=my_action;end">我的材料链接</a>感谢你的帮助。 - Paz
嘿,如果我想在安卓版的谷歌浏览器中打开一个网站,应该怎么做?我需要在意图和操作中放什么? - Matheus Oliveira
我的看法是,如果链接嵌入HTML电子邮件中,则无法正常工作,因为Gmail会删除此类超链接。 - danipenaperez
intent:语法的文档可以在这里找到:https://developer.chrome.com/multidevice/android/intents - David
显示剩余4条评论

6

AndroidManifest 声明:

<activity android:name="...">
<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="hostName"
     android:path="path"
     android:scheme="schemeName" />
   </intent-filter>
</activity>

您可以让其调用。
<a href = "schemeName://hostName/path">

或者在浏览器中添加类似的参数到URL中。
<a href = "schemeName://hostName/path?id=1&name=mark">

你可以调用JS方法来完成这个任务。代码如下: - aolphn

1

林平君提到的一种方法,另一种方法是通过调用js方法,代码如下:

function openAActivity(){
     window.location = "schemeName://hostName/path"

}

这个方法会发送一个Android意图来启动指定的活动。

-5

第一种方法:

<html><head></head><body>
<iframe src="YourApp://profile/blabla" width="1px" height="1px" scrolling="no" frameborder="0"></iframe>
<script>
setTimeout(function() {
window.location = "http://YourSite.com/profile/blabla"; }, 4000
                );
</script>
</body>
</html>

或者
第二种方法https://dev59.com/fmkv5IYBdhLWcg3w9lWi#24023048


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接