忽然有一天玩360手機助手下載東西,可是點擊安裝直接就跳轉到App中,臥槽,這比較新奇,之前真沒以爲有這麼一回事,才疏學淺吶。html
1、經過html頁面打開Android本地的appandroid
簡單的html頁面web
<html> 瀏覽器
<head>app
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>ide
</head>ui
<body>url
<a href="m://my.com/">打開app</a><br/>htm
</body>webview
</html>
二、在Android本地app的配置
在AndroidManifest的清單文件裏的intent-filte中加入以下元素:
<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="my.com"
android:scheme="m" />
</intent-filter>
2、如何經過這個方法獲取網頁帶過來的數據能
能打開好像就那麼回事,可是能傳數據就牛X了
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="m://my.com/?arg0=0&arg1=1">打開app</a><br/>
</body>
</html>
(1).假如你是經過瀏覽器打開這個網頁的,那麼獲取數據的方式爲:
Uri uri = getIntent().getData(); String test1= uri.getQueryParameter("arg0"); String test2= uri.getQueryParameter("arg1");
(2)若是使用webview訪問該網頁,獲取數據的操做爲:
webView.setWebViewClient(new WebViewClient(){ @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Uri uri=Uri.parse(url); if(uri.getScheme().equals("m")&&uri.getHost().equals("my.com")){ String arg0=uri.getQueryParameter("arg0"); String arg1=uri.getQueryParameter("arg1"); }else{ view.loadUrl(url); } return true; } });