通过html调起app,并传递数据
生活随笔
收集整理的這篇文章主要介紹了
通过html调起app,并传递数据
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、通過html頁面打開Android本地的app
?
1、首先在編寫一個簡單的html頁面
<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/">打開app</a><br/></body></html>2、在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" /><dataandroid:host="my.com" android:scheme="m" /> </intent-filter>示例截圖如下:
?
然后使用“手機瀏覽器”或者“webview”的方式打開這個本地的html網頁,點擊“打開APP”即可成功開啟本地的指定的app
?
二、如何通過這個方法獲取網頁帶過來的數據
?
只能打開就沒什么意思了,最重要的是,我們要傳遞數據,那么怎么去傳遞數據呢?
我們可以使用上述的方法,把一些數據傳給本地app,那么首先我們更改一下網頁,代碼修改后:
<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(){@Overridepublic 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;}});
此文為轉載, 原文地址:http://www.cnblogs.com/yejiurui/p/3413796.html
總結
以上是生活随笔為你收集整理的通过html调起app,并传递数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (已解决)显卡(N卡)设置独显后,指定程
- 下一篇: 程序员都有黑客梦,聊聊渗透工程师主要学什