Share photo on Facebook Android SDK -


i'm trying share photo on facebook android sdk.

the problem bitmap image null. code:

public void sharephoto(view view) {         if (session.getinstance().getuserface().getbestphoto() == null) {             intent = new intent(intent.action_pick, android.provider.mediastore.images.media.external_content_uri);             startactivityforresult(i, result_load_image);         }     }      @override     protected void onactivityresult(int requestcode, int resultcode, intent data) {         super.onactivityresult(requestcode, resultcode, data);         if (requestcode == result_load_image && resultcode == result_ok && null != data) {             uri selectedimage = data.getdata();             string[] filepathcolumn = {mediastore.images.media.data};             cursor cursor = getcontentresolver().query(selectedimage, filepathcolumn, null, null, null);             cursor.movetofirst();             int columnindex = cursor.getcolumnindex(filepathcolumn[0]);             string picturepath = cursor.getstring(columnindex);             cursor.close();             log.d("picture path", picturepath);             bitmapfactory.options options = new bitmapfactory.options();             try {                 bitmap image = bitmapfactory.decodefile(picturepath, options);                 uploadphoto(image);             } catch (outofmemoryerror e) {                 try {                     options = new bitmapfactory.options();                     options.insamplesize = 2;                     bitmap image = bitmapfactory.decodefile(picturepath, options);                     uploadphoto(image);                 } catch (exception ex) {                     log.e("exception", ex.tostring());                 }             }         }     }      private void uploadphoto(bitmap image) {         log.d("image", "" + image);         sharephoto photo = new sharephoto.builder()                 .setbitmap(image)                 .build();         sharephotocontent content = new sharephotocontent.builder()                 .addphoto(photo)                 .build();         sharedialog.show(mainactivity.this, content);     } 

you can try getting bitmap inputstream instead. use this,

bitmapfactory.decodestream(resolver.openinputstream(uri), null, options); 

where resolver contentresolver , uri returned data.getdata();

you won't need query database, unless wanna check filenotfoundexception.


Comments