大家好我必须在WebView中查看base64中的pdf这样做我使用下面的代码,但它不起作用!我怎么能想象它呢?我试过这个解决方案,但似乎没有用,WebView中没有显示任何内容!它能是什么?
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 pdf 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);
}
}
});
}