Reputation: 317
I have found what looks like an array of bytes, but when I attempt to decode it using bitmaps decodeByteArray, it returns null
String mediaString = t.entities.media.toString();
String[] mediaArray = mediaString.split("(?=@)");
byte[] mediaBytes = mediaArray[1].getBytes();
can anybody help me find a way to retrieve the image so I can display it?
Upvotes: 2
Views: 976
Reputation: 5024
i am getting image only if it is available like:
String mediaImageUrl = null;
if (tweet.entities.media != null) {
String type = tweet.entities.media.get(0).type;
if (type.equals("photo")) {
mediaImageUrl = tweet.entities.media.get(0).mediaUrl;
}
else {
mediaImageUrl = "'";
}
System.out.println("mediaImageUrl" + mediaImageUrl);
}
If u using type attributes u can easily differentiates image/video from userTimeLine
Upvotes: 0
Reputation: 176
Image url
String mediaImageUrl = tweet.entities.media.get(0).url;
Bitmap mediaImage = getBitmapFromURL(mediaImageUrl);
Bitmap mImage = null;
Decode the image
private Bitmap getBitmapFromURL(final String mediaImageUrl) {
try {
Thread t = new Thread() {
public void run() {
try {
URL url = new URL(mediaImageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inScaled = false;
mImage = BitmapFactory.decodeStream(input, null, options);
} catch (Exception e) {
e.printStackTrace();
}
}
};
t.start();
} catch (Exception e) {
e.printStackTrace();
}
return mImage;
}
Upvotes: 1