Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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);
                }
            }
        });


    }
Posted
Updated 6-Jun-18 23:48pm

1 solution

WebView does not support showing PDF files (besides using external services like the Google Docs viewer which requires an URL to the PDF file). You have to choose another method. Just search the web for something like "android show pdf".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900