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

Android 應用指定瀏覽器開發(fā)實例

 更新時間:2016年10月23日 11:04:45   投稿:lqh  
這篇文章主要介紹了Android 應用指定瀏覽器開發(fā)實例的相關資料,需要的朋友可以參考下

  本文主要講解Android瀏覽器的開發(fā)實例,有三部分內(nèi)容:啟動Android默認瀏覽器、指定瀏覽器進行訪問以及打開本地的html文件。

       一、啟動Android默認瀏覽器

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)用起手機默認的瀏覽器訪問。

  二、指定瀏覽器進行訪問

  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、啟動其他瀏覽器(當然該瀏覽器必須安裝在機器上)

       只要修改以下相應的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文件的時候,一定要指定某個瀏覽器,而不能采用方式一來瀏覽,具體示例代碼如下:

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); 

  關鍵點是調(diào)用了"content”這個filter。

       以前有在win32編程的朋友,可能會覺得用這種形式”file://sccard/help.html“是否可以,可以很肯定的跟你說,默認的瀏覽器設置是沒有對"file“這個進行解析的,如果要讓你的默認android瀏覽器有這個功能需要自己到android源碼修改manifest.xml文件,然后自己編譯瀏覽器代碼生成相應的apk包來重新在機器上安裝。

  大體的步驟如下:

  1、打開packages/apps/Browser/AndroidManifest.xml文件把加到相應的<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”這個形式了。

        感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持! 

相關文章

最新評論