1

我必须在应用程序中显示来自远程URL链接的不同类型的文档。我使用谷歌文件在网页视图这样在android web视图中使用google doc显示.DOCX文件给出错误

private WebView mWvHome = (WebView) view.findViewById(R.id.wv_home); 
    mWvHome.setWebChromeClient(new WebChromeClient() { 
       public void onProgressChanged(WebView view, int progress) { 

       } 
      }); 
    mWvHome.setWebViewClient(new WebViewClient() { 
       @Override 
       public boolean shouldOverrideUrlLoading(WebView view, String url) { 
        view.loadUrl(url); 
        return false; 
       } 
       @Override 
       public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) { 
       } 
      });  
    mWvHome.getSettings().setJavaScriptEnabled(true); // enable javascript 
    //Pasting a Fixed URL link to the file I am getting this Error. 
    mWvHome.loadUrl("http://docs.google.com/gview?embedded=true&url=http://followitdc.cloudapp.net/FollowitMediaAPIv4/images/bb629006-d930-4fbe-b9ec-91895dc5133c.docx"); 

这是我的布局文件

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white"> 

    <ProgressBar 
     android:id="@+id/progress" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/margin_normal" 
     android:layout_alignParentTop="true" 
     android:max="100" 
     android:progress="0" 
     android:progressDrawable="@drawable/custom_progressbar" 
     android:visibility="visible" /> 

    <WebView 
     android:id="@+id/wv_home" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/progress" /> 


    <RelativeLayout 
     android:id="@+id/rl_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@id/progress" 
     android:background="@color/white"> 

     <ProgressBar 
      style="?android:attr/progressBarStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" /> 

    </RelativeLayout> 

</RelativeLayout> 

装载正从谷歌文档这个响应后。

enter image description here

小于2MB .docx格式的文件加载某些文件小于2MB也没有加载。这是什么问题?它是文件大小问题还是文件错误?由于文件在Google文档联机编辑器中以及在Microsoft Word上正常工作。任何帮助将不胜感激。

+0

http://docs.google.com/gview?embedded=true&url这不适用于某些android设备。 – MathaN

+0

我应该怎么做才能修复它@MathaN –

+0

如果您有后端团队告诉他们给出链接来阅读文档文件。会好起来的。我为我的申请做了同样的事情。 – MathaN

回答

0

WebView讨论的,在使用loadDataWithBaseURL,web视图可以访问本地设备文件(通过“文件”方案的URL)

仅当baseurl指比其它的方案的“http”,“https”时,' ftp','ftps','about'或'javascript'。

但据我所知,WebView目前不支持显示office文档。如果您的目标只是将一些HTML作为您的用户界面的一部分显示,那么这可能是好的。

请在此SO后检查的解决方案 - Android how to open a .doc extention file和这个职位在GitHub上 - AndroidDocxToHtml这可能会有帮助。

1

经过一番斗争,我已经达到this link中,他们有提到“Office Web Apps的浏览器”文件扩展名状(“.PPT'.PPTX“的.doc”,“.DOCX”在线应用程序,”的.xls',.xlsx等),你只需要提供你的WebView在线文档链接

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

谷歌在线文档视图应用简化版,处理DOC和DOCX文件以便我,并给予上面的错误我已经提到。但使用Office Live应用程序进行Office文件扩展之后,所有工作都很顺利。

相关问题