【问题标题】:How to launch android application from my html5 mobile web application如何从我的 html5 移动 Web 应用程序启动 android 应用程序
【发布时间】:2014-09-03 17:17:36
【问题描述】:

我是 android 和移动开发新手

我已经在 html5 中创建了移动应用程序,我们已经准备好在 android 中开发的用于扫描目的的 android 应用程序,我需要从在浏览器上运行的 html5 应用程序打开这个 android 应用程序。我不知道怎么打电话,我看到一些应用程序,其中移动设备会要求打开应用程序(例如 facebook 移动应用程序中的相机和媒体播放器)。请让我知道是否有任何机制让用户可以从我的 html 移动应用程序中单击按钮,并且移动设备将打开安装在我的移动设备上的我的 android 应用程序。

【问题讨论】:

    标签: android html jquery-mobile


    【解决方案1】:

    要实现这一点,请使用带有 <data> 元素的 <intent-filter>

    例如,要处理指向 yourdomain.com 的所有链接,您可以将其放在 AndroidManifest.xml 中的 <activity> 中:

    <intent-filter>
        <data android:scheme="http" android:host="yourdomain.com"/>
        <action android:name="android.intent.action.VIEW" />
    </intent-filter>
    

    <intent-filter>
        <data android:scheme="my.special.scheme" />
        <action android:name="android.intent.action.VIEW" />
    </intent-filter>
    

    现在在 Html 页面中给出锚标记,如

    <a href="my.special.scheme">
    

    实际上魔法存在于您的清单文件中 您需要将活动声明为可浏览。

    示例代码。

     <activity
                android:name=".SplashActivity"
                android:label="@string/app_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="mywebsite.com"
                        android:path="/somepath/openNativeApp"
                        android:scheme="nativescheme" />
                </intent-filter>
            </activity>
    

    你的 Anchor 标签看起来像

     <a href="nativescheme://mywebsite.com/somepath/openNativeApp">
    

    【讨论】:

    • 您好 Hardik Trivedi,您能分享任何示例应用程序源代码吗?这对我有很大帮助。
    • 编辑了答案。提供了我的一个应用程序的示例代码。
    • 您好 Hardik Trivedi,已解决感谢您的帮助。我可以从 Web 应用程序调用 Android 应用程序。我需要更多帮助。如果 Android 应用程序在移动设备中不可用。它显示错误消息“找不到页面......”,但我们不会向客户显示该消息。如果移动设备上没有安卓应用程序,我们会指导客户连接谷歌应用商店。请分享有什么办法。
    猜你喜欢
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    相关资源
    最近更新 更多