2013-10-01 258 views
2

我有本地pdf文件鏈接的HTML頁面。我想在瀏覽器(chrome,opera,dolphin)內部打開這個pdf文件,而無需連接互聯網。可能你知道插件,可以打開PDF文件(無需下載)瀏覽器或方法或其他內容?如何在android瀏覽器中打開pdf文件?

+1

向我們展示您迄今爲止所做的研發。你有沒有試圖在Stackoverflow本身上搜索? –

+0

我正在尋找第二週。但docs.google不適合(需要主動連接),一組插件(完美的查看器pdf,金山辦公室e.t)不能幫助解決問題。 – isxaker

回答

2

遺憾的是目前在Android設備上的本地瀏覽器不支持此類型的文件。讓我們看看是否在4.0+我們將能夠做到這一點。

+0

提供哪些類型的文件? – isxaker

2

我曾經使用過的解決方案是使用Google文檔打開它們。下面的代碼

_webView.loadUrl("https://docs.google.com/gview?embedded=true&url="+ url); 
+0

沒有連接到互聯網 – isxaker

1

用途:

CustomWebView webView = (CustomWebView) rootView.findViewById(R.id.webView); 
webView.loadUrl("https://docs.google.com/gview?embedded=true&url=" + yourUrl); 

製作CustomWebView類,如下:

public class CustomWebView extends WebView { 
    private Context context; 

    private ProgressDialog progressDialog; 

    public CustomWebView(Context context) { 
     super(context); 
     this.context = context; 
     init(); 
    } 

    public CustomWebView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     this.context = context; 
     init(); 
    } 

    public CustomWebView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
     this.context = context; 
     init(); 
    } 

    private void init() { 
     setWebSetting(); 
    } 

    private void setWebSetting() { 
     WebSettings webSettings = getSettings(); 
     webSettings.setJavaScriptEnabled(true); 
     webSettings.setPluginsEnabled(true); 
     webSettings.setBuiltInZoomControls(true); 
     webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); 
     webSettings.setLightTouchEnabled(false); 
     setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY); 
     setWebViewClient(new CustomWebViewClient()); 
    } 

    class CustomWebViewClient extends WebViewClient { 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      return false; 
     } 

     @Override 
     public void onPageStarted(WebView view, String url, Bitmap favicon) { 
      super.onPageStarted(view, url, favicon); 
      progressDialog = ProgressDialog.show(context, null, 
        context.getString(R.string.msg_please_wait)); 
      progressDialog.setCancelable(false); 
     } 

     @Override 
     public void onPageFinished(WebView view, String url) { 
      super.onPageFinished(view, url); 
      progressDialog.dismiss(); 
     } 
    } 
} 
+0

沒有連接到互聯網 – isxaker

+0

您需要主動連接到互聯網使用這種方法。 – Swetank