本文介绍了在android上显示base64 pdf到webview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi guys I have to view a pdf in base64 in a WebView to do so I used the code below but it does not work! How can I visualize it? I tried this solution but it does not seem to work, nothing is shown in the WebView! What can it be?





我尝试过的方法:





What I have tried:

<pre lang="java">
@Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        final Button btnGeneraRapportino = (Button)view.findViewById(R.id.buttongenera_rapportino);
        final WebView img= (WebView) view.findViewById(R.id.WebView_Rapportino);

        btnGeneraRapportino.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {



                Rapportino r = new Rapportino();
                String ImageBase64 = r.GeneraRapportinoPrivato("prova"); //This method return String with Image into Base64
                  try
                  {
                      String urlString = getActivity().getIntent().getStringExtra(ImageBase64);
                      String mimeType = getActivity().getIntent().getStringExtra("MimeType");
                      WebSettings settings = img.getSettings();
                      settings.setDefaultTextEncodingName("utf-8");
                      String base64 = Base64.encodeToString(urlString.getBytes(), Base64.DEFAULT);
                      img.loadData(urlString, "text/html; charset=utf-8", "base64");
                }
                catch (Exception ex){
                    System.out.print("Errore: "+ex);
                }
            }
        });


    }

推荐答案


这篇关于在android上显示base64 pdf到webview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 23:14