2013-05-08 228 views
2

假設我有一個網頁,並在Android設備上的瀏覽器中加載該頁面。我期望的是,當我點擊網頁上的按鈕時,可以打開一個應用程序。在Android中,如何在瀏覽器中打開應用程序

有沒有辦法做到這一點?非常感謝。

+0

是的,有。在你的場景中,你是該網站的網絡開發人員嗎?或者您是否打算在該設備上預安裝Android應用程序?無論哪種情況,都可以完成。這只是你將使用的確切機制取決於你將控制哪一部分。 – 2013-05-08 06:12:53

回答

0

就可以實現這一點使用<intent-filter><data>。 例如,處理所有鏈接sample.com,你會把這裏面你在你的AndroidManifest.xml:

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

這一個被Felix在他的回答很好地解釋here

希望這幫助你...

0

如果您可以選擇自定義相關應用程序,則可以爲應用程序特有的特定URI方案添加Intent Filter。然後,在網頁按鈕的點擊事件中,使用此URI方案啓動您的應用程序。

例如,Google Play使用計劃通過鏈接打開Goog​​le Play應用。

0

使用IntentFilter的IT可能.. 焯芬出下面的代碼: -

<intent-filter> 
    <data android:scheme="**myapp**" /> 
    <action android:name="android.intent.action.VIEW" /> 
    <category android:name="android.intent.category.DEFAULT" /> 
    <category android:name="android.intent.category.BROWSABLE" /> <--Not positive if this one is needed 
    ... 
</intent-filter> 

現在你就可以開始你的應用程序一樣的myapp://

0

你可以使用getIntent()。getData()它返回一個Uri對象。然後可以使用Uri。*方法來提取所需的數據。例如,假設用戶點擊一個鏈接http://twitter.com/status/1234

Uri data = getIntent().getData(); 
String scheme = data.getScheme(); // "http" 
String host = data.getHost(); // "twitter.com" 
List<String> params = data.getPathSegments(); 
String first = params.get(0); // "status" 
String second = params.get(1); // "1234"  

你可以做上面的任何地方的活動,但你可能會想這樣做在的onCreate()。您也可以使用params.size()來獲取Uri中的路徑段數。查看javadoc或android開發人員網站,瞭解可用於提取特定部分的其他Uri方法。

相關問題