I'm trying to use a separate service to fetch tweets using twitters search
API
I have given permission in the android manifest file
here is my manifest entry for the service, i run it in a separate process:
<service android:name=".cube1.FetchTweets"
android:process=":fetchTweetProcess">
here is my code for the service:
package com.example.android.livecubes.cube1;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
public class FetchTweets extends Service
{
final String LOG_TAG="FetchTweets";
private Handler serviceHandler = null;
@Override
public void onStart( Intent intent, int startId )
{
Log.d( LOG_TAG, "onStart" );
}
@Override
public IBinder onBind( Intent intent )
{
IBinder binder = null;
return binder;
}
@Override
public void onCreate()
{
super.onCreate();
Log.d( LOG_TAG,"onCreate" );
serviceHandler = new Handler();
serviceHandler.postDelayed( new RunTask(),10 );
Log.d( LOG_TAG,"after runtask" );
}
@Override
public void onDestroy()
{
super.onDestroy();
Log.d( LOG_TAG,"onDestroy" );
}
class RunTask implements Runnable
{
public void run()
{ Log.d( LOG_TAG,"In Run" );
String output="";
String str;
try{
Log.d( LOG_TAG,"In Try" );
URL url = new URL("http://search.twitter.com/search.json?q=egypt&rpp=1");
Log.d( LOG_TAG,"URL: "+url.toString() );
// Read all the text returned by the server
URLConnection conn = url.openConnection();
Log.d( LOG_TAG,"Conn Open" );
conn.setConnectTimeout(5000);
conn.setReadTimeout(7000);
BufferedReader in = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
Log.d( LOG_TAG,"BR" );
while ((str = in.readLine()) != null)
{
output=str;// str is one line of text; readLine() strips the newline
character(s)
}
in.close();
Log.i(LOG_TAG,"Output: "+output);
JSONObject jTweet = new JSONObject(output);
JSONArray tweet = jTweet.getJSONArray("results");
String tweetText = tweet.getJSONObject(0).getString("text").toString();
Log.i(LOG_TAG,"Tweet: "+tweetText);
}
catch (Exception e)
{Log.e(LOG_TAG,"Error: "+e.getMessage());}
serviceHandler.postDelayed( this, 30000 );
Log.i(LOG_TAG,"Done");
}
}
}
When i run it the log gives
02-20 19:37:59.345: ERROR/FetchTweets(287): Error: Host is unresolved:
search.twitter.com:80
and my internet is working.
Can any one help me with why this is happening? any ideas would be great.
Thank you
--
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