从网页打开android应用程序

Open android application from a web page

本文关键字:android 应用程序 网页      更新时间:2024-06-26

我知道,要从网页内的链接打开android应用程序,我们必须在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页面,也许可以通过定义页面中的特定操作?

谢谢,

帕斯。


已解决:

多亏了David,我找到了一个解决方案:

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

试试这个:

让你的链接看起来像这样:

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

还可以看看从android浏览器启动自定义android应用程序

AndroidMainfest声明:

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

单向林平君saied,另一种方法是调用js方法,代码如下:

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

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

第一种方式:

<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://stackoverflow.com/a/24023048/2165415