The webview under Anroid5.0 displays the local image,
In the past, webview in Android used the ontent: // + package name + Path Method to display local images. Later, after 5.0, the security protocol was improved and this method was not supported, later I found that the img tag can be used in this way. I converted the local image into a bitmap, and then converted the bitmap into a Base64
Public static String imgToBase64 (Bitmap bitmap ){
ByteArrayOutputStream out = null;
Try {
Out = new ByteArrayOutputStream ();
Bitmap. compress (Bitmap. CompressFormat. JPEG, 100, out );
Out. flush ();
Out. close ();
Byte [] imgBytes = out. toByteArray ();
Return Base64.encodeToString (imgBytes, Base64.DEFAULT );
} Catch (Exception e ){
// TODO Auto-generated catch block
Return null;
} Finally {
Try {
Out. flush ();
Out. close ();
} Catch (IOException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
}
}
Add data: image/jpeg; Base64 before the obtained base64 string,
String pic = "data: image/jpeg; base64," + imgToBase64 (bitmap );
Then upload the pic to html through javascript. Note that @ JavascriptInterface needs to be added to the javascript method after Android5.0.
Finally, just set the src = pic of the img tag.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.