Display image in WebView

If you are so lazy as me! Display image in WebView is a good choice.

Display image in WebView


package com.example.androidwebviewphoto;

import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.webkit.WebView;

public class MainActivity extends Activity {
 
 WebView webView;
 String imagePath = "/tmp/testphoto.jpg";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        
        webView = new WebView(this);
        setContentView(webView);
        
        String fullUrl = "file://" 
          + Environment.getExternalStorageDirectory().getAbsolutePath().toString() 
          + "/" 
          + imagePath;
        webView.loadUrl(fullUrl);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setLoadWithOverviewMode(true);

    }
    
}


0 Response to "Display image in WebView"

Posting Komentar