Androidのブラウザのリンクをクリックするとアプリを起動できるようにする
自分用のメモです。
このようなHTMLをAndroidのブラウザで表示するとします。
call from browserのリンクを踏むとAndroid.Manifestにintent受信の設定をしているアプリを起動できます。
<html> <body> <head><title>test</title></head> <center><a href="launchfrombrowzercall:/kokohananndemoii/">call from browser</a></center> </body> </html>
上記HTML中で定義されている「launchfrombrowzercall」(好きな文字で良い)というschemeを
マニフェストファイルにも
のように指定します。
Android.Manifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.myexample.android.applaunch" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="7" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- ブラウザからの起動するための定義 <a href="launchfrombrowzercall:/kokohananndemoii/">call from browser</a> のようにlaunchfrombrowzercallというschemeを付けると当アプリをブラウザから起動できる --> <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="launchfrombrowzercall" /> </intent-filter> <!-- ブラウザからの起動するための定義終わり --> </activity> </application> </manifest>