从网页打开 android 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11773958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open android application from a web page
提问by Paz
I know that for opening android application from a link inside a web page we have to write the following in the AndroidManifest.xml
:
我知道要从网页内的链接打开 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>
The problem is that I wrote it in the following way:
问题是我是这样写的:
<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>
I didn't add android.intent.action.VIEW
and instead I added my own action that i made.
I can't change it because the version is already released.
我没有添加android.intent.action.VIEW
,而是添加了我自己的操作。我无法更改它,因为该版本已经发布。
The question is,
问题是,
if there's a way to make the application run from JavaScript or simple html page, maybe by defining the specific action in the page?
如果有办法让应用程序从 JavaScript 或简单的 html 页面运行,也许是通过在页面中定义特定的操作?
Thanks,
谢谢,
Paz.
帕斯。
SOLVED:
解决了:
Thanks to David I found a solution:
感谢大卫我找到了一个解决方案:
<a href="intent://my_host#Intent;scheme=my_scheme;action=my_action;end">Link to my stuff</a>
回答by David Wasser
Try this:
尝试这个:
Make your links look like this:
让你的链接看起来像这样:
<a href="intent:#Intent;action=my_action;end">Link to my stuff</a>
Also have a look at Launch custom android application from android browser
回答by u5761591
AndroidMainfest declare:
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>
you can let to invoke
你可以让调用
<a href = "schemeName://hostName/path">
or add param similar url in brower
或在浏览器中添加参数类似的网址
<a href = "schemeName://hostName/path?id=1&name=mark">
回答by aolphn
One way as 林平君 saied,and another way by invoking js method ,code as follow:
一种是林平君说的,另一种是调用js方法,代码如下:
function openAActivity(){
window.location = "schemeName://hostName/path"
}
this method will send an Android intent to start specified activity.
此方法将发送一个 Android 意图来启动指定的活动。
回答by T.Todua
1st way:
第一种方式:
<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>
OR
2nd way:
https://stackoverflow.com/a/24023048/2165415