Kamis, 12 Juli 2012

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 komentar:

Posting Komentar

Copyright © 2012 Codding News All Right Reserved