㈠ 安卓開發怎麼在APP內部調用手機系統瀏覽器打開指定html並獲取HTML的數據
android開發_如何調用 瀏覽器訪問網頁和Html文件
一、啟動android默認瀏覽器
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就可以調用起手機默認的瀏覽器訪問。
二、指定相應的瀏覽器訪問
1、指定android自帶的瀏覽器訪問
( 「com.android.browser」:packagename ;「com.android.browser.BrowserActivity」:啟動主activity)
Intent intent= new Intent();
intent.setAction('android.intent.action.VIEW');
Uri content_url = Uri.parse('http://www.cnblogs.com');
intent.setData(content_url);
intent.setClassName('com.android.browser','com.android.browser.BrowserActivity');
startActivity(intent);
2、啟動其他瀏覽器(當然該瀏覽器必須安裝在機器上)
只要修改以下相應的packagename 和 主啟動activity即可調用其他瀏覽器
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文件的時候,一定要指定某個瀏覽器,而不能採用方式一來瀏覽,具體示例代碼如下
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);
關鍵點是調用了」content「這個filter。
以前有在win32編程的朋友,可能會覺得用這種形式」file://sccard/help.html「是否可以,可以很肯定的跟你說,默認的瀏覽器設置是沒有對」file「這個進行解析的,如果要讓你的默認android瀏覽器有這個功能需要自己到android源碼修改manifest.xml文件,然後自己編譯瀏覽器代碼生成相應的apk包來重新在機器上安裝。
大體的步驟如下:
1、打開 packages/apps/Browser/AndroidManifest.xml文件把加到相應的後面就可以了
2、重新編譯打包,安裝,這樣子,新的瀏覽器就支持」file「這個形式了
有興趣的可以去試試。
㈡ 安卓手機如何打開後綴名為html的文件
這是一個網頁文件,一般都是網址。
所以隨便用一個瀏覽器打開就行了。
㈢ Android瀏覽器如何打開本地html文件
android 瀏覽器
打開本地html文件的方法
有些html文件放在本地磁碟和sdcard,如何用打開這個網頁呢?
這種應用在測試時非常有用。
有2個方法:
1.使用文件管理器
如ES等,需要幸運的是你的文件管理器直接用瀏覽器打開。
2.在瀏覽器輸入地址
訪問本地磁碟和SD卡上的HTML,前部分content://com.android.htmlfileprovider是Provider的標准,後面是程序目錄。
比如sdcard的tesl.html
直接在瀏覽器里輸入content://com.android.htmlfileprovider/sdcard/test.html回車就可以看到網頁了。
在代碼
webView.loadUrl("content://com.android.htmlfileprovider/sdcard/test.html")
如果是其它程序的私有html文件,這樣做會失敗。
這是由於com.android.htmlfileprovider的許可權不夠,如果是重寫一個私有的HtmlProvider位於同一個應用中,應該能解決問題。然後就參考了原來的com.android.htmlfileprovider
源代碼,改寫了下。問題解決了,使用私有的HTMLProvider,可以輕松的訪問手機內存中,程序私有目錄下的html文件。
網上有例子,你可以搜索!
㈣ android怎麼打開html文件
在android自帶瀏覽器中打開本地文件方法:
在瀏覽器地址欄中輸入file://路徑
如在sdcard中有01.html這個文件,想用android自帶瀏覽器打開它,只要在地址欄中輸入file://sdcard/01.html即可
㈤ android 怎樣用html文件
html頁面(命名:Android.html放在assets文件夾下):::::
<!DOCTYPEhtmlPUBLIC"-//WAPFORUM//DTDXHTMLMobile1.0//EN""
<htmlxmlns="">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<scriptlanguage="javascript"type="text/javascript">
functionget4Android(str){
document.getElementById("show").innerHTML="Thisisamessagefromandroid:"+str;
}
</script>
</head>
<body>
<divid="show"></div>
</body>
</html>
Text.java代碼:::
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.text.Editable;
importandroid.view.MotionEvent;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.view.View.OnTouchListener;
importandroid.webkit.WebSettings;
importandroid.webkit.WebView;
importandroid.webkit.WebViewClient;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.TextView;
{
privateButtonbutton;
privateTextViewtext;
privateWebViewweb;
privateEditTextedit;
privateHandlerhandler;
privatevoidinitView(){
button=(Button)this.findViewById(R.id.button2);
web=(WebView)this.findViewById(R.id.webView1);
edit=(EditText)this.findViewById(R.id.editText1);
button.setOnClickListener(this);
}
privatevoidsetWebView(){
web.setWebViewClient(newWebViewClient());
web.requestFocus();
WebSettingssetting=web.getSettings();
setting.setJavaScriptEnabled(true);
web.setOnTouchListener(newOnTouchListener(){
@Override
publicbooleanonTouch(Viewv,MotionEventevent){
web.requestFocus();
returnfalse;
}
});
web.addJavascriptInterface(newSendAndroid(),"theKey");
web.loadUrl("file:///android_asset/android.html");
}
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initView();
setWebView();
handler=newHandler(){
publicvoidhandleMessage(android.os.Messagemsg){
Stringstr=msg.obj.toString();
text.setText(str);
};
};
}
@Override
publicvoidonClick(Viewv){
Editableeditable=edit.getText();
web.loadUrl("javascript:get4Android(""+editable.toString()
+"")");
}
classSendAndroid{
(finalStringstr){
newThread(newRunnable(){
@Override
publicvoidrun(){
System.out.println("******"+str);
Messagemes=handler.obtainMessage();
mes.obj=str;
handler.sendMessage(mes);
}
}).start();
}
}
}
主要是:web.loadUrl("javascript:get4Android(""+editable.toString()+"")");中的「javascript:get4Android」要和html中的【functionget4Android(str){
document.getElementById("show").innerHTML="Thisisamessagefromandroid:"+str;
}】方法名相同
㈥ html文件在安卓手機上怎麼閱讀
1、第一步:打開微信,點開網友發來的「你好」文件,點擊「開始下載」