WebView network loading PDF

Source: Internet
Author: User

Main. xml is as follows: [html] <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" tools: context = ". mainActivity "> <WebView android: id =" @ + id/webView "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: layout_centerHorizontal =" true "android: l Ayout_centerVertical = "true"/> </RelativeLayout> MainActivity: [java] package c. c; import android. OS. bundle; import android. webkit. webView; import android. webkit. webSettings. layoutAlgorithm; import android. app. activity;/*** Demo Description: * use WebView to load network PDF resources * Method 1: Use the browser of the device to open the pdf * Method 2: after Google service resolution is used, open pdf * In mWebView. Note: * it is best to connect to VPN */public class MainActivity extends Activity {private WebView mWeb during testing. View; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); init ();} private void init () {mWebView = (WebView) findViewById (R. id. webView); // method 1 loadPDF1 (); // method 2 // loadPDF2 ();} // Method 1: open pdf private void loadPDF1 () in the browser that comes with the device () {mWebView. getSettings (). setJavaScriptEnabled (true); mWebView. getSettings (). setsuppzoom zoom (true); mWe BView. getSettings (). setDomStorageEnabled (true); mWebView. getSettings (). setAllowFileAccess (true); mWebView. getSettings (). setPluginsEnabled (true); mWebView. getSettings (). setUseWideViewPort (true); mWebView. getSettings (). setBuiltInZoomControls (true); mWebView. requestFocus (); mWebView. getSettings (). setLoadWithOverviewMode (true); mWebView. getSettings (). setLayoutAlgorithm (LayoutAlgorithm. SINGLE_COLUMN ); String weburl = "http://www8.cao.go.jp/okinawa/8/2012/0409-1-1.pdf"; mWebView. loadUrl ("http://docs.google.com/gview? Embedded = true & url = "+ response url);} // Method 2: Open the pdf private void loadPDF2 () {mWebView in the mWebView after Google resolution. getSettings (). setJavaScriptEnabled (true); mWebView. getSettings (). setsuppzoom zoom (true); mWebView. getSettings (). setDomStorageEnabled (true); mWebView. getSettings (). setAllowFileAccess (true); mWebView. getSettings (). setPluginsEnabled (true); mWebView. getSettings (). setUseWideViewPort (true); mWebView. getSet Random (). setBuiltInZoomControls (true); mWebView. requestFocus (); www.2cto.com mWebView. getSettings (). setLoadWithOverviewMode (true); mWebView. getSettings (). setLayoutAlgorithm (LayoutAlgorithm. SINGLE_COLUMN); String inline url = "http://www8.cao.go.jp/okinawa/8/2012/0409-1-1.pdf"; String data = "<iframe src = 'HTTP: // docs.google.com/gview? Embedded = true & url = "+ response url +" '"+" width = '000000' height = '000000' style = 'border: none;'> </iframe> "; mWebView. loadData (data, "text/html", "UTF-8 ");}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.