. deSelby . , (PNG JPG) Facebook, / sqlite, .
, , , , Facebook, .
private static Drawable fetchPhoto(ContentResolver cr, int source, String path) {
Drawable image = null;
myDB mDb = myDB.getInstance();
Cursor iCursor = mDb.fetchImage(cr, path);
if(iCursor != null && iCursor.moveToFirst()) {
byte[] bb = iCursor.getBlob(iCursor.getColumnIndex(Images.IMAGE));
if(iCursor != null) iCursor.close();
image = new BitmapDrawable(BitmapFactory.decodeByteArray(bb, 0, bb.length));
} else {
if(iCursor != null) iCursor.close();
try
{
InputStream is = (InputStream) new URL(path).getContent();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
byte[] barray = baf.toByteArray();
bis.close();
is.close();
long id = mDb.writeImage(cr,source,path,barray);
image = new BitmapDrawable(BitmapFactory.decodeByteArray(barray, 0, barray.length));
}catch (Exception error) {
}
}
return image;
}
My writeImage (. ).
Images.IMAGE BLOB .
, [] BLOB .
(utc), Facebook api .
public long writeImage(ContentResolver contentResolver, int source, String path, byte[] image) {
Time now = new Time();
now.setToNow();
ContentValues initialValues = new ContentValues();
initialValues.put(Images.IMAGE, image);
initialValues.put(Images.SOURCE, source);
initialValues.put(Images.PATH, path);
initialValues.put(Images.UTC, now.toMillis(false));
if(source == 0) initialValues.put(Images.DIRTY, 1);
Uri newUri = contentResolver.insert(Images.CONTENT_URI, initialValues);
String Id = newUri.getPathSegments().get(1);
return Long.parseLong(Id);
}
db, , , . ( FYI).
rowId = db.insert(IMAGES_TABLE, null, values);