1 需要在AndroidManifest.xml 中添加過濾器
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT"/>
<data
android:scheme="myscheme"
android:host="myhost"
android:pathPrefix="/myapp/open"
/>
</intent-filter>
</activity>
2 Html5代碼
<!DOCTYPE HTML>
<html >
<meta charset="utf-8">
<script>
function openapp(){
window.location.href = 'myscheme://myhost/myapp/open?data=mydata';
}
</script>
<body>
<input type="button" value="打開app" onclick="openapp()">
</body>
</html>
3 在mainActivity中可以對傳遞過來的資料進行處理
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Uri uridata = this.getIntent().getData();
String mydata = uridata.getQueryParameter("data");
}