Install Url for WebView

I am trying to install an image for WebView for my application.

I use the code below to set the image to my WebView ,

  String imageUrl = " file:///android_res/drawable/dinner_menu.png"; WebView wv = (WebView) findViewById(R.id.yourwebview); wv.getSettings().setBuiltInZoomControls(true); wv.loadUrl(imageUrl); 

This is great for Android 2.2 and higher .

But if I try to run the code in 2.1 or lower , it will show an error like,

The requested file was not found /android_res/drawable/dinner_menu.png .

Can anybody help me.

+6
source share
1 answer

Try placing the image in your resources folder and upload it using:

 WebView webView = new WebView(this); webView.loadUrl("file:///android_asset/dinner_menu.png"); setContentView(webView); 

It should work on earlier versions of Android, but you need to manually control different versions of your image for different screen sizes / densities.

+20
source

Source: https://habr.com/ru/post/890738/


All Articles