Android 瀏覽器的開發(fā)實(shí)例分享
本文主要講解Android瀏覽器的開發(fā)實(shí)例,有三部分內(nèi)容:啟動Android默認(rèn)瀏覽器、指定瀏覽器進(jìn)行訪問以及打開本地的html文件。
一、啟動Android默認(rèn)瀏覽器
Java代碼
Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("http://www.cnblogs.com"); intent.setData(content_url); startActivity(intent);
這樣子,android就可以調(diào)用起手機(jī)默認(rèn)的瀏覽器訪問。
二、指定瀏覽器進(jìn)行訪問
1、指定android自帶的瀏覽器訪問
(“com.android.browser”:packagename;“com.android.browser.BrowserActivity”:啟動主activity)
Java代碼
Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("http://www.jizhuomi.com/android"); intent.setData(content_url); intent.setClassName("com.android.browser","com.android.browser.BrowserActivity"); startActivity(intent);
2、啟動其他瀏覽器(當(dāng)然該瀏覽器必須安裝在機(jī)器上)
只要修改以下相應(yīng)的packagename和主啟動activity,即可調(diào)用其他瀏覽器。
intent.setClassName("com.android.browser","com.android.browser.BrowserActivity");
- uc瀏覽器":"com.uc.browser", "com.uc.browser.ActivityUpdate“
- opera:"com.opera.mini.android", "com.opera.mini.android.Browser"
- qq瀏覽器:"com.tencent.mtt", "com.tencent.mtt.MainActivity"
三、打開本地html文件
打開本地的html文件的時(shí)候,一定要指定某個瀏覽器,而不能采用方式一來瀏覽,具體示例代碼如下:
Java代碼
Intent intent = new Intent(); intent.setAction("android.intent.action.VIEW"); Uri content_url = Uri.parse("content://com.android.htmlfileprovider/sdcard/help.html"); intent.setData(content_url); intent.setClassName("com.android.browser","com.android.browser.BrowserActivity"); startActivity(intent);
關(guān)鍵點(diǎn)是調(diào)用了"content”這個filter。
以前有在win32編程的朋友,可能會覺得用這種形式”file://sccard/help.html“是否可以,可以很肯定的跟你說,默認(rèn)的瀏覽器設(shè)置是沒有對"file“這個進(jìn)行解析的,如果要讓你的默認(rèn)android瀏覽器有這個功能需要自己到android源碼修改manifest.xml文件,然后自己編譯瀏覽器代碼生成相應(yīng)的apk包來重新在機(jī)器上安裝。
大體的步驟如下:
1、打開packages/apps/Browser/AndroidManifest.xml文件把加到相應(yīng)的<intent-filter>后面就可以了。
XML/HTML代碼 <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="file" /> </intent-filter>
2、重新編譯打包,安裝,這樣子,新的瀏覽器就支持"file”這個形式了。
以上就是對Android 瀏覽器的開發(fā)的示例代碼,希望能幫助開發(fā)此功能的朋友,謝謝大家的支持!
- Android實(shí)現(xiàn)分享功能
- Android Zxing生成二維碼經(jīng)典案例分享
- Android登錄界面的實(shí)現(xiàn)代碼分享
- Android實(shí)現(xiàn)第三方授權(quán)登錄、分享以及獲取用戶資料
- Android常用進(jìn)度條效果分享
- Android獲取高清app圖標(biāo)代碼分享
- 分享一個Android設(shè)置圓形圖片的特別方法
- 分享Android仿刮獎效果控件
- Android超實(shí)用的Toast提示框優(yōu)化分享
- android微信支付源碼分享
- 分享Android中Toast的自定義使用
- Android 實(shí)現(xiàn)微信,微博,微信朋友圈,QQ分享的功能
相關(guān)文章
Android實(shí)現(xiàn)自定義ImageView的圓角矩形圖片效果
android顯示圓角矩形的圖片其原理就是首先獲取到圖片的Bitmap,然后進(jìn)行裁剪對應(yīng)的圓角矩形的bitmap,然后在onDraw()進(jìn)行繪制圓角矩形圖片輸出2018-05-05詳解Android StrictMode嚴(yán)格模式的使用方法
這篇文章主要介紹了Android StrictMode嚴(yán)格模式的使用方法,需要的朋友可以參考下2018-01-01解決EditText、ListView以及GridView同時(shí)使用,輸入法自動跳出來的方法
本篇文章是對在Android中EditText、ListView以及GridView同時(shí)使用,輸入法自動跳出來的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05Android?Activity通用懸浮可拖拽View封裝的思路詳解
這篇文章主要介紹了Android?Activity通用懸浮可拖拽View封裝,實(shí)現(xiàn)思路是通過封裝通用的基礎(chǔ)懸浮View,繼承通用View,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-07-07Android 自定義view和屬性動畫實(shí)現(xiàn)充電進(jìn)度條效果
近期項(xiàng)目中需要使用到一種類似手機(jī)電池充電進(jìn)度的動畫效果,以前沒學(xué)屬性動畫的時(shí)候,是用圖片+定時(shí)器的方式來完成的,下面給大家分享android自定義view和屬性動畫實(shí)現(xiàn)充電進(jìn)度條2016-12-12Android實(shí)現(xiàn)手機(jī)振動設(shè)置的方法
這篇文章主要介紹了Android實(shí)現(xiàn)手機(jī)振動設(shè)置的方法,涉及Android頁面布局、屬性及功能設(shè)置的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09Flutter實(shí)現(xiàn)不同縮放動畫效果詳解
這篇文章主要為大家詳細(xì)介紹了Flutter利用不同組件(ScaleTransition、SizeTransition、AnimatedSize和AnimatedBuilder)實(shí)現(xiàn)不同縮放動畫效果,感興趣的可以動手嘗試一下2022-06-06