2014-09-03 46 views
0

推出Android應用程序,我是新來的Android和移動開發如何從我的HTML5移動Web應用程序

我已經創建HTML5的移動應用程序,我們有一個Android應用程序準備在Android的開發掃描的目的,我需要從瀏覽器上運行的html5應用程序中打開此android應用程序。我不確定如何打電話,我看到了一些應用程序,其中移動設備將要求應用程序打開(例如在facebook移動應用程序中的相機和媒體播放器)。請讓我知道是否有任何機制,用戶可以點擊我的HTML手機應用程序中的按鈕,手機將打開我的手機上安裝的Android應用程序。

回答

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

實際上,magic存在於清單文件中 您需要將活動聲明爲可瀏覽。

示例代碼。

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

而且你的錨標籤看起來像

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

嗨Hardik特里維迪,你可以共享任何示例應用程序的源代碼。它會幫助我很多。 – 2014-09-03 09:05:32

+0

編輯答案。提供了我的應用程序中的示例代碼。 – 2014-09-03 09:18:01

+0

嗨哈迪克Trivedi,它解決了感謝您的幫助。我可以從Web應用程序調用安卓應用程序。我需要更多的幫助。如果andriod應用程序在手機中不可用。它顯示錯誤消息「Page Not Found .......」,但我們不會向客戶顯示該消息。我們有引導客戶連接谷歌應用程序商店如果Andriod應用程序不可用在移動。請分享一下有沒有辦法。 – 2014-09-03 10:31:50

相關問題