firebase和google doc打开pdf文件

时间:2017-03-02 07:16:33

标签: android pdf firebase

我正在尝试使用谷歌文档和firebase为Android应用程序打开pdf文件。我遇到的问题是,当我使用来自firebase的任何pdf文件时,我收到此消息“无预览可用”,如果我使用任何外部链接,它的工作完全正常

这是我使用的代码

1 promise, Boolean requiresSynchronization)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at PushSharp.Apple.ApnsConnection.<connect>d__1c.MoveNext() in c:\D\visualStudioProjects\PushSharp-masterMowazi\PushSharp-master\PushSharp.Apple\ApnsConnection.cs:line 329
   --- End of inner exception stack trace ---
   at PushSharp.Apple.ApnsConnection.<connect>d__1c.MoveNext() in c:\D\visualStudioProjects\PushSharp-masterMowazi\PushSharp-master\PushSharp.Apple\ApnsConnection.cs:line 374
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at PushSharp.Apple.ApnsConnection.<SendBatch>d__7.MoveNext() in c:\D\visualStudioProjects\PushSharp-masterMowazi\PushSharp-master\PushSharp.Apple\ApnsConnection.cs:line 143
   --- End of inner exception stack trace ---
   at PushSharp.Apple.ApnsServiceConnection.<Send>d__0.MoveNext() in c:\D\visualStudioProjects\PushSharp-masterMowazi\PushSharp-master\PushSharp.Apple\ApnsServiceConnection.cs:line 49<---

此链接有效“http://www.pdf995.com/samples/pdf.pdf” 但是当我使用来自firebase的任何链接时它都不起作用。在firebase上,我尝试了“gs://”和“https://”。

1 个答案:

答案 0 :(得分:0)

pdf_url=getArguments().getString("pdf_url");

        final ProgressDialog pDialog = new ProgressDialog(getActivity());
        pDialog.setTitle("Course PDF");
        pDialog.setMessage("Loading...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);

        webView=view.findViewById(R.id.pdfviewr);
        webView.getSettings().setJavaScriptEnabled(true);

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                pDialog.show();
            }

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

        String url="";
        try {
            url=URLEncoder.encode(pdf_url,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        webView.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url="+url);

        return view;
    }
  

// url = URLEncoder.encode(pdf_url,“ UTF-8”);

     

添加它以将URL转换为UTF-8,并且可以正常工作。