如何从我的html5移动Web应用程序启动Android应用程序

时间:2014-09-03 07:55:37

标签: android html5 jquery-mobile

我是Android和移动Dev的新手

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

1 个答案:

答案 0 :(得分:0)

要实现这一目标,<intent-filter>具有<data>元素。

例如,要处理指向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">