-
前言:
html中启动本地app
-
html:
<a href="appscheme://apphost/openwith?name=zhang3&age=30">Start App</a>
格式: [scheme]://[host]/[path]?[query]
html代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Start App</title>
</head>
<body>
<a href="appscheme://apphost/openwith?name=zhang3&age=30">Start App</a>
</body>
</html>
-
android 代码
AndroidManifest.xml中, 在要启动的Activity中添加如下:
<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="appscheme" android:host="apphost" android:pathPrefix="/openwith"/>
</intent-filter>
获取参数, 启动的Activity中:
try {
Uri uri = getIntent().getData();
String query = uri.getQuery();
String name = uri.getQueryParameter("name");
String age = uri.getQueryParameter("age");
Log.d("appscheme-", "name: " + name + ", age: " + age + ", query: " + query);
} catch (Exception e) {
Log.e("appscheme-", e.getMessage(), e);
}
网友评论