Hi, the link actually returns a png file, not a webpage.
So you will have to download that file and show it in a imageview.



something like below.

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.Toast;

public class GetImageActivity extends Activity {
    /** Called when the activity is first created. */
    static String res;
    Bitmap bitmap;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        new Thread(new Runnable() {   
            public void run(){  
  
                final Bitmap bitmap = DownloadImage();
                
                GetImageActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        ImageView img = (ImageView) 
findViewById(R.id.imageView1);
                        img.setImageBitmap(bitmap);
                        Toast.makeText(getApplicationContext(), "response 
code = "+res, Toast.LENGTH_LONG).show();        
                    }
                });

            }
    }).start();

        
        //
    }
    
        private static InputStream OpenHttpConnection(String urlString)   
            throws IOException
            {
                InputStream in = null;
                int response = -1;
                       
                URL url = new URL(urlString); 
                URLConnection conn = url.openConnection();
                         
                if (!(conn instanceof 
HttpURLConnection))                     
                    throw new IOException("Not an HTTP connection");
                
                try{
                    HttpURLConnection httpConn = (HttpURLConnection) conn;
                    httpConn.setAllowUserInteraction(false);
                    httpConn.setInstanceFollowRedirects(true);  
                    httpConn.setRequestMethod("GET");
                    httpConn.connect(); 

                    response = httpConn.getResponseCode();   
                    
                    if (response == HttpURLConnection.HTTP_OK) {    
                        in = httpConn.getInputStream();   
                    }                     
                    
                    res = Integer.toString(response);
                  }
                catch (Exception ex)
                {
                    throw new IOException("Error connecting");             
                }
                return in;     
            }
            public static Bitmap DownloadImage()
            {        
                Bitmap bitmap = null;
                InputStream in = null;        
                try {
                    
                    in = 
OpenHttpConnection("https://chart.googleapis.com/chart?chs=250x100&chd=t:60,40&cht=p3&chl=Hello|World");
                    bitmap = BitmapFactory.decodeStream(in);
                    in.close();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
                return bitmap;                
            }
}

babu

On Tuesday, June 26, 2012 3:29:57 PM UTC+5:30, Remo wrote:
>
> Hi All,
>
> I am trying to load google chart api in webView. But doesn't show 
> graphical image. I also allowed internet permission in manifest. 
>
> For your reference i mention the my code below
>
> <?xml version="1.0" encoding="utf-8"?>
> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
>    android:orientation="vertical"
>    android:layout_width="fill_parent"
>    android:layout_height="fill_parent"
>    >
> <TextView
>    android:layout_width="fill_parent"
>    android:layout_height="wrap_content"
>    android:text="@string/hello"
>    />
> <WebView
>    android:id="@+id/embeddedwebview"
>    android:layout_width="wrap_content"
>    android:layout_height="wrap_content"
>    android:layout_gravity="center"
>    />
> </LinearLayout>
>
> ----------------------
>
> public class GoogleChartActivity extends Activity {
>   
>  WebView embeddedWebView;
>  
>  String jj = "
> https://chart.googleapis.com/chart?chs=100x100&chd=t:60,40&cht=p3&chl=Hello|World
> ";
>    /** Called when the activity is first created. */
>    @Override
>    public void onCreate(Bundle savedInstanceState) {
>        super.onCreate(savedInstanceState);
>        setContentView(R.layout.main);
>        embeddedWebView = (WebView)findViewById(R.id.embeddedwebview);
>        embeddedWebView.loadUrl(jj);
>    }
> }
>
> -------------------------------------
>
> <?xml version="1.0" encoding="utf-8"?>
> <manifest xmlns:android="http://schemas.android.com/apk/res/android";
>     package="com.app.googleChat"
>     android:versionCode="1"
>     android:versionName="1.0" >
>
>     <uses-sdk android:minSdkVersion="15" />
>     
>     <uses-permission android:name="android.permission.INTERNET" />
>
>     <application
>         android:icon="@drawable/ic_launcher"
>         android:label="@string/app_name" >
>         <activity
>             android:name=".GoogleChartActivity"
>             android:label="@string/app_name" >
>             <intent-filter>
>                 <action android:name="android.intent.action.MAIN" />
>
>                 <category android:name="android.intent.category.LAUNCHER" 
> />
>             </intent-filter>
>         </activity>
>     </application>
>
> </manifest>
>
>
> Is there anything I am missing in manifest or some kind of changes I have 
> to make in webview. please help.
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to