Wednesday, September 25, 2013

using IBinder class to Bind service

There are total 3 ways to bind a service with application components
  1. Using IBinder class
  2. Using Messanger class
  3. Using AIDL
The life is a process of learning even after some bad happening we are going on and learning things. someone asked me about the Binding Services and i was unable to answer  and that after i tried to work on the same.

Create a project and have a main activity with Name MainActivity.

Implementing the Binder

to implement the binder creat a class SomeServic which extends Service class, i create an inner class with name LocalBinder which is inner class and inside SomeService.

package com.example.bindserviceusingbinderclass;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class SomeService extends Service {

IBinder mBinder = new LocalBinder();

@Override
public IBinder onBind(Intent intent) {
return mBinder;
}

public class LocalBinder extends Binder {
public SomeService getServerInstance() {
return SomeService.this;
}
}

public String getTime() {
SimpleDateFormat mDateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
return mDateFormat.format(new Date());
}
}


finally we need to start service at Mainactivity

Binding the Client to the Service

package com.example.bindserviceusingbinderclass;

import com.example.bindserviceusingbinderclass.SomeService.LocalBinder;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;



public class MainActivity extends Activity {

boolean mBounded;
SomeService mServer;
TextView text;
Button button;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

text = (TextView) findViewById(R.id.text);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
text.setText(mServer.getTime());
}
});
}

@Override
protected void onStart() {
super.onStart();
Intent mIntent = new Intent(this, SomeService.class);
bindService(mIntent, mConnection, BIND_AUTO_CREATE);
};

ServiceConnection mConnection = new ServiceConnection() {

public void onServiceDisconnected(ComponentName name) {
Toast.makeText(MainActivity.this, "Service is disconnected", 1000).show();
mBounded = false;
mServer = null;
}

public void onServiceConnected(ComponentName name, IBinder service) {
Toast.makeText(MainActivity.this, "Service is connected", 1000).show();
mBounded = true;
LocalBinder mLocalBinder = (LocalBinder) service;
mServer = mLocalBinder.getServerInstance();
}
};

@Override
protected void onStop() {
super.onStop();
if (mBounded) {
unbindService(mConnection);
mBounded = false;
}
};
@Override
protected void onDestroy() {
super.onStop();
if (mBounded) {
unbindService(mConnection);
mBounded = false;
}
};
}


do not forget to work with manifest for the service.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.bindserviceusingbinderclass"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.bindserviceusingbinderclass.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".SomeService" />
    </application>
    

</manifest>

the activity_main.xml looks like

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/text"
        android:layout_below="@+id/text"
        android:layout_marginLeft="36dp"
        android:layout_marginTop="54dp"
        android:text="Button" />

</RelativeLayout>



Wednesday, June 26, 2013

Android Downloading MP3 to sd card

Some guy asked me the question regarding to how to download the mp3 files to the sd card and i wrote the program for this purpose please have a look and enjoy the practices.

Create a project with the name DownloadMp3 and have a main activity with following code

package com.jitesh.downloadmp3;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

private static String fileName = "file.mp3";
private static final String MY_URL = "http://www.virginmegastore.me/Library/Music/CD_001214/Tracks/Track1.mp3";

private Button play;
private TextView message;

private ProgressDialog pDialog;

// Progress dialog type (0 - for Horizontal progress bar)
public static final int progress_bar_type = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

play = (Button) findViewById(R.id.download);
message=(TextView)findViewById(R.id.message);
play.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
new DownloadFileFromURL().execute(MY_URL);
}
});

}

/**
* Showing Dialog
* */
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case progress_bar_type:
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading file. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
return pDialog;
default:
return null;
}
}

public void downloadStreams() {
try {
URL url = new URL(MY_URL);
HttpURLConnection c = (HttpURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();

String PATH = Environment.getExternalStorageDirectory()
+ "/download/";
Log.v("log_tag", "PATH: " + PATH);
File file = new File(PATH);
if (!file.exists()) {
file.mkdirs();
}
File outputFile = new File(file, fileName);
FileOutputStream fos = new FileOutputStream(outputFile);

InputStream is = c.getInputStream();

byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = is.read(buffer)) != -1) {
fos.write(buffer, 0, len1);
}
fos.close();
is.close();
} catch (IOException e) {
Log.e("log_tag", "Error: " + e);
}
Log.v("log_tag", "Check: ");
}

class DownloadFileFromURL extends AsyncTask<String, String, String> {

/**
* Before starting background thread Show Progress Bar Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(progress_bar_type);
}

/**
* Downloading file in background thread
* */
protected String doInBackground(String... f_url) {
int count;
try {
URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
// getting file length
int lenghtOfFile = conection.getContentLength();

// input stream to read file - with 8k buffer
InputStream input = new BufferedInputStream(url.openStream(),
8192);

// Output stream to write file
OutputStream output = new FileOutputStream("/sdcard/"
+ fileName);

byte data[] = new byte[1024];

long total = 0;

while ((count = input.read(data)) != -1) {
total += count;
// publishing the progress....
// After this onProgressUpdate will be called
publishProgress("" + (int) ((total * 100) / lenghtOfFile));

// writing data to file
output.write(data, 0, count);
}

// flushing output
output.flush();

// closing streams
output.close();
input.close();

} catch (Exception e) {
Log.e("Error: ", e.getMessage());
}

return null;
}

/**
* Updating progress bar
* */
protected void onProgressUpdate(String... progress) {
// setting progress percentage
pDialog.setProgress(Integer.parseInt(progress[0]));
}

/**
* After completing background task Dismiss the progress dialog
* **/
@Override
protected void onPostExecute(String file_url) {
// dismiss the dialog after the file was downloaded
dismissDialog(progress_bar_type);

// Displaying downloaded image into image view
// Reading image path from sdcard
String imagePath = Environment.getExternalStorageDirectory()
.toString() + fileName;
// setting downloaded into image view
// my_image.setImageDrawable(Drawable.createFromPath(imagePath));
message.setText("File downloaded and saved to directory==>"+imagePath);
}

}
}


the main layout file is presented here which is activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

    <Button
        android:id="@+id/download"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Download" >
    </Button>

</RelativeLayout>

the strings.xml is having following attributes

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">DownloadMp3</string>
    <string name="hello_world">please click the button to download the stream!</string>
    <string name="menu_settings">Settings</string>

</resources>


the manifest should have following permissions

<uses-permission android:name="android.permission.INTERNET" />
     
    <!-- Permission to write to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

and it should look like below given manifest attributes

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jitesh.downloadmp3"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.jitesh.downloadmp3.MainActivity"
            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>
<uses-permission android:name="android.permission.INTERNET" />
     
    <!-- Permission to write to external storage -->
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

the screenshots are given below



Also the source code can be downloaded from http://www.mediafire.com/download/18axcocxot725pl/DownloadMp3.zip


Friday, April 5, 2013

Android Creating App Widget

Here i am presenting an idea of a widget on the main screen of the device. 




Creat a project and have main activity with name

1)JiteshActivity.java
package com.jitesh.uselesswidget;

import com.jitesh.uselesswidget.R;

import android.app.Activity;
import android.os.Bundle;

public class JiteshActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
    }
}

2)UselessWidgetProvider .java

package com.jitesh.uselesswidget.widgetprovider;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import com.jitesh.uselesswidget.R;
import com.jitesh.uselesswidget.settings.Preferences;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.RemoteViews.RemoteView;

public class UselessWidgetProvider extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("http://search.twitter.com/search.json?q=twitter");
BasicResponseHandler handler = new BasicResponseHandler();
String response = null;
String text=null;
Date d=null;
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
try{
response = client.execute(get,handler);
if(response!=null){
JSONObject object = new JSONObject(response);
JSONArray array = object.getJSONArray("results");
if(array.length()>0){
JSONObject tweet = array.getJSONObject(0);
text = tweet.getString("text");
String dateStr = tweet.getString("created_at");
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z",Locale.US);
d = sdf.parse(dateStr);
Log.v(getClass().getName(),"Date: "+d+" Text: "+text);
Editor e = preferences.edit();
e.putString(Preferences.PREFERENCE_TWEET, text);
e.putLong(Preferences.PREFERENCE_TIME, d.getTime());
e.commit();
}
}
}
catch(Exception e){
e.printStackTrace();
}
SimpleDateFormat sdf2 = new SimpleDateFormat("d/MM/yy HH:mm");
if(d==null && text==null){
text = preferences.getString(Preferences.PREFERENCE_TWEET, "Indisponible en ce moment!");
Long dateLong = preferences.getLong(Preferences.PREFERENCE_TIME, -1);
if(dateLong!=-1)d=new Date(dateLong);
}
if(d!=null && text!=null){
for(int i = 0; i<appWidgetIds.length;i++){
int appWidgetId = appWidgetIds[i];
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
remoteViews.setTextViewText(R.id.textViewText, text);
remoteViews.setTextViewText(R.id.textViewTime, sdf2.format(d));
appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
}
}
}
}

3)Preferences .java

package com.jitesh.uselesswidget.settings;

public class Preferences {
public static final String PREFERENCE_TWEET = "com.jitesh.uselesswidget.preference.tweet";
public static final String PREFERENCE_TIME = "com.jitesh.uselesswidget.preference.time";
}


4)main.xml

<?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"
    android:gravity="center_horizontal|center_vertical"
    >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello"
        android:layout_margin="20dp"
        style="@android:style/TextAppearance.Medium"
        />

</LinearLayout>

5) res/layout/widget.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/appwidget_bg" >

<ImageView
   android:id="@+id/imageViewWidget"
   android:layout_width="68dp"
   android:layout_height="68dp"
   android:src="@drawable/reynders"
   android:layout_margin="8dp"
   />
<TextView
   android:id="@+id/textViewText"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_toRightOf="@id/imageViewWidget"
   android:textColor="#FFFFFF"
   android:layout_marginTop="4dp"/>
<TextView
   android:id="@+id/textViewTime"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentRight="true"
   android:layout_alignParentBottom="true"
   android:textColor="#BBBBBB"
   android:layout_margin="4dp"
   />

</RelativeLayout>

7) res/xml/uselessappwidgetprovider.xml

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="294dp"
    android:minHeight="72dp"
    android:updatePeriodMillis="1800000"
    android:initialLayout="@layout/widget"    
>
</appwidget-provider>

8)res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Go to main screen and please make long press  on the screen and select widget " twitter widget "</string>
    <string name="app_name">Twitter Widget</string>

</resources>

9)manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.jitesh.uselesswidget"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="4" />
    <uses-permission 
        android:name="android.permission.INTERNET"
        />

    <application
        android:icon="@drawable/icon"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".JiteshActivity"
            android:theme="@android:style/Theme.Light">
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <receiver android:name=".widgetprovider.UselessWidgetProvider">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
            </intent-filter>
            <meta-data android:name="android.appwidget.provider"
                android:resource="@xml/uselessappwidgetprovider"/>
        </receiver>
    </application>

</manifest>


copy the resources to drawable










Monday, April 1, 2013

Android Using Weather API'S of yahoo

Please  read the doc at http://developer.yahoo.com/weather/

and have close look on the apis

http://where.yahooapis.com/geocode?q=ahmedabad=%5Byourappidhere%5D

http://weather.yahooapis.com/forecastrss?w=2502265

Make a new project and have the MainActivity with following code


package com.exercise.AndroidYahooWeatherDOM;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class AndroidYahooWeatherDOMActivity extends Activity {

TextView weather;

class MyWeather{
String description;
String city;
String region;
String country;

String windChill;
String windDirection;
String windSpeed;

String sunrise;
String sunset;

String conditiontext;
String conditiondate;

public String toString(){

return "\n- " + description + " -\n\n"
+ "city: " + city + "\n"
+ "region: " + region + "\n"
+ "country: " + country + "\n\n"

+ "Wind\n"
+ "chill: " + windChill + "\n"
+ "direction: " + windDirection + "\n"
+ "speed: " + windSpeed + "\n\n"

+ "Sunrise: " + sunrise + "\n"
+ "Sunset: " + sunset + "\n\n"

+ "Condition: " + conditiontext + "\n"
+ conditiondate +"\n";

}
}

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        weather = (TextView)findViewById(R.id.weather);
        
        
        String weatherString = QueryYahooWeather();
        Document weatherDoc = convertStringToDocument(weatherString);

        MyWeather weatherResult = parseWeather(weatherDoc);
        weather.setText(weatherResult.toString());
    }
    
    private MyWeather parseWeather(Document srcDoc){
   
    MyWeather myWeather = new MyWeather();
   
    //<description>Yahoo! Weather for New York, NY</description>
    myWeather.description = srcDoc.getElementsByTagName("description")
    .item(0)
    .getTextContent();
   
    //<yweather:location city="New York" region="NY" country="United States"/>
    Node locationNode = srcDoc.getElementsByTagName("yweather:location").item(0);
    myWeather.city = locationNode.getAttributes()
.getNamedItem("city")
.getNodeValue()
.toString();
myWeather.region = locationNode.getAttributes()
.getNamedItem("region")
.getNodeValue()
.toString();
myWeather.country = locationNode.getAttributes()
.getNamedItem("country")
.getNodeValue()
.toString();

//<yweather:wind chill="60" direction="0" speed="0"/>
Node windNode = srcDoc.getElementsByTagName("yweather:wind").item(0);
myWeather.windChill = windNode.getAttributes()
.getNamedItem("chill")
.getNodeValue()
.toString();
myWeather.windDirection = windNode.getAttributes()
.getNamedItem("direction")
.getNodeValue()
.toString();
myWeather.windSpeed = windNode.getAttributes()
.getNamedItem("speed")
.getNodeValue()
.toString();

//<yweather:astronomy sunrise="6:52 am" sunset="7:10 pm"/>
Node astronomyNode = srcDoc.getElementsByTagName("yweather:astronomy").item(0);
myWeather.sunrise = astronomyNode.getAttributes()
.getNamedItem("sunrise")
.getNodeValue()
.toString();
myWeather.sunset = astronomyNode.getAttributes()
.getNamedItem("sunset")
.getNodeValue()
.toString();

//<yweather:condition text="Fair" code="33" temp="60" date="Fri, 23 Mar 2012 8:49 pm EDT"/>
Node conditionNode = srcDoc.getElementsByTagName("yweather:condition").item(0);
myWeather.conditiontext = conditionNode.getAttributes()
.getNamedItem("text")
.getNodeValue()
.toString();
myWeather.conditiondate = conditionNode.getAttributes()
.getNamedItem("date")
.getNodeValue()
.toString();

    return myWeather;
    }
    
    private Document convertStringToDocument(String src){
    Document dest = null;
   
    DocumentBuilderFactory dbFactory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder parser;

    try {
    parser = dbFactory.newDocumentBuilder();
dest = parser.parse(new ByteArrayInputStream(src.getBytes()));
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this, 
    e1.toString(), Toast.LENGTH_LONG).show();
} catch (SAXException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this, 
    e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this, 
    e.toString(), Toast.LENGTH_LONG).show();
}
   
    return dest;
    }
    
    private String QueryYahooWeather(){
    // use the api to get WOEID which i used directly in this demo
    //http://where.yahooapis.com/geocode?q=bangalore=%5Byourappidhere%5D
    String qResult = "";
    String queryString = "http://weather.yahooapis.com/forecastrss?w=2295420";
   
    HttpClient httpClient = new DefaultHttpClient();
        HttpGet httpGet = new HttpGet(queryString);
        
        try {
        HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();
       
        if (httpEntity != null){
        InputStream inputStream = httpEntity.getContent();
        Reader in = new InputStreamReader(inputStream);
        BufferedReader bufferedreader = new BufferedReader(in);
        StringBuilder stringBuilder = new StringBuilder();
       
        String stringReadLine = null;

        while ((stringReadLine = bufferedreader.readLine()) != null) {
        stringBuilder.append(stringReadLine + "\n");
        }
       
        qResult = stringBuilder.toString();
        }

} catch (ClientProtocolException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this, 
    e.toString(), Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(AndroidYahooWeatherDOMActivity.this, 
    e.toString(), Toast.LENGTH_LONG).show();
}
   
        return qResult;
    }
}

the main.xml is as shown below


<?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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="hello buddy" />
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView
            android:id="@+id/weather"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
    </ScrollView>

</LinearLayout>