Our social:

Latest Post

Sunday 17 February 2013

google6f91343f73185652

abc

Thursday 14 February 2013

How to download image from server in android programming,how to retrive image file form server in android programming



How  to download image from server in android programming
In this tutorial I will tell you how to download image from server or a given url .first of all create  a new project an in eclipse .
After this go to main_activity.xml and paste the given code in this file
?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
    android:layout_width=”fill_parent”
    android:layout_height=”fill_parent”
    android:orientation=”vertical” >
<ImageView
    android:id=”@+id/img”
    android:layout_width=”wrap_content”
    android:layout_height=”wrap_content”
    android:layout_gravity=”center” />  
</LinearLayout>

After this go to main.java and paste the below given code in this file
import android.widget.ImageView;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
public class NetworkingActivity extends Activity {
    ImageView img;   
   
    private 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();                                
            }                    
        }
        catch (Exception ex)
        {
            Log.d(“Networking”, ex.getLocalizedMessage());
            throw new IOException(“Error connecting”);
        }
        return in;    
    }
   
    private Bitmap DownloadImage(String URL)
    {       
        Bitmap bitmap = null;
        InputStream in = null;       
        try {
            in = OpenHttpConnection(URL);
            bitmap = BitmapFactory.decodeStream(in);
            in.close();
        } catch (IOException e1) {
            Log.d(“NetworkingActivity”, e1.getLocalizedMessage());           
        }
        return bitmap;               
    }
       
    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
        protected Bitmap doInBackground(String... urls) {
            return DownloadImage(urls[0]);
        }
       
        protected void onPostExecute(Bitmap result) {
            ImageView img = (ImageView) findViewById(R.id.img);
            img.setImageBitmap(result);
        }
    }
     @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        new DownloadImageTask().execute(
            http://www.mayoff.com/5-01cablecarDCP01934.jpg”);
    }
}

The highlighted line is the address of server from where you want to download image here you can give the any url address of an image of any site.
In eclipse  it may be commas(“ ”) give error so remove these all commas and insert new from keyboard.

Wednesday 13 February 2013

how to send a message from pc to android emulator


How to send a text message from pc to android emulator

Step 1:Open an emulator or start emulator

step 2: When emutaor destop screen comes then open eclipse DDMS portion as show below

Step 3:
Follow below step:




Step 4:
 Now type message in text area and give some number value on "INCOMMING NUMBER " field  and then select sms check box and type text and then press  send button

Step 5:
Now check emulator screen there will be text message alert