Unable to receive share image - Android 6.0 -
i using code provided afilechooser able shared image inside application. images gallery work ok if use image inside google chrome , try share it, gives me npe imagepath
null.
string imagepath = getpath(getactivity(), imageuri);
my uri
identified mediastore (and) general code:
else if ("content".equalsignorecase(uri.getscheme())) { if (isgooglephotosuri(uri)) return uri.getlastpathsegment(); return getdatacolumn(context, uri, null, null); }
however inside getdatacolumn()
cursor dump follows:
08-24 12:00:58.196 13186 13256 receivephotos d cursor is: >>>>> dumping cursor android.content.contentresolver$cursorwrapperinner@e110803 08-24 12:00:58.196 13186 13256 receivephotos d 0 { 08-24 12:00:58.196 13186 13256 receivephotos d _data=null 08-24 12:00:58.196 13186 13256 receivephotos d } 08-24 12:00:58.196 13186 13256 receivephotos d <<<<< 08-24 12:00:58.196 13186 13256 receivephotos d cursor column index is: 0
getdatacolumn() method:
public static string getdatacolumn(context context, uri uri, string selection, string[] selectionargs) { cursor cursor = null; final string column = "_data"; final string[] projection = { column }; try { cursor = context.getcontentresolver().query(uri, projection, selection, selectionargs,null); log.d("receivephotos", " cursor is: " + databaseutils.dumpcursortostring(cursor)); if (cursor != null && cursor.movetofirst()) { final int column_index = cursor.getcolumnindexorthrow(column); log.d("receivephotos", " cursor column index is: " + column_index); return cursor.getstring(column_index); } } { if (cursor != null) cursor.close(); } return null; }
imageuri log
08-24 12:07:32.780 13629 13696 receivephotos d image uri: content://com.android.chrome.fileprovider/images/screenshot/1472011649310784004280.jpg
phone & os details
sony e5823 on android 6.0.1
you cannot , should not attempt ever underlying path corresponding uri - in vast majority of cases app never have access path itself, through uri.
thankfully, can binary data of image uri directly:
inputstream in; bitmap bitmap = null; try { in = getcontentresolver().openinputstream(imageuri); // inputstream. // here we'll bitmap @ full size bitmap = bitmapfactory.decodestream(in); } catch (ioexception e) { // went wrong } { if (in != null) { try { in.close(); } catch (ioexception ignored) {} } } // have bitmap.
Comments
Post a Comment