欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 瀏覽器的開發(fā)實(shí)例分享

 更新時(shí)間:2016年08月30日 17:34:38   投稿:lqh  
本文主要介紹Android 瀏覽器的開發(fā),這里提供詳細(xì)的資料及示例代碼,有興趣的小伙伴可以參考下

 本文主要講解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");

  1.   uc瀏覽器":"com.uc.browser", "com.uc.browser.ActivityUpdate“
  2.   opera:"com.opera.mini.android", "com.opera.mini.android.Browser"
  3.   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ā)此功能的朋友,謝謝大家的支持!

相關(guān)文章

最新評論