Saturday, March 19, 2011

[android-developers] Re: (JSON) Download fails in 2.1 but works in 2.2

Solved it by using:


/**
* This seems to work in both Android 2.1 and 2.2
*/
public static String loadStream(String link) throws Exception {
URL url = new URL(link);
Log.d(TAG, "Loading from URL=" + url);
InputStream is = null;
DataInputStream dis;
is = url.openStream();
dis = new DataInputStream(new BufferedInputStream(is));
StringBuffer sb = new StringBuffer();
String s = null;
while ((s = dis.readLine()) != null) {
// Log.d(TAG, s);
sb.append(s);
}
return sb.toString();
}

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate