Cordova resolveLocalFileSystemURL error code 1000 in Android -
when use cordova function resolvelocalfilesystemurl type of file uri (like content://com.android.providers.downloads.documents/document/some_doc) have error code 1000. use cordova 5.1 , 5 version of android installed on smartphone.
adb logcat shows this:
w/system.err(28721): java.lang.nullpointerexception: attempt invoke virtual method 'long java.lang.long.longvalue()' on null object reference w/system.err(28721): @ org.apache.cordova.file.contentfilesystem.getfilemetadataforlocalurl(contentfilesystem.java:130) w/system.err(28721): @ org.apache.cordova.file.filesystem.exists(filesystem.java:130) w/system.err(28721): @ org.apache.cordova.file.fileutils.resolvelocalfilesystemuri(fileutils.java:624) w/system.err(28721): @ org.apache.cordova.file.fileutils.access$400(fileutils.java:51) w/system.err(28721): @ org.apache.cordova.file.fileutils$14.run(fileutils.java:383) w/system.err(28721): @ org.apache.cordova.file.fileutils$25.run(fileutils.java:566) w/system.err(28721): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112) w/system.err(28721): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587) w/system.err(28721): @ java.lang.thread.run(thread.java:818)
is way open files cordova?
i have fixed issue. in android 5, cursor documentcursor not media cursor means looking wrong column. when column not found, plugin tries set primitive long null caused nullpointerexception.
@override public jsonobject getfilemetadataforlocalurl(localfilesystemurl inputurl) throws filenotfoundexception { long size = -1; long lastmodified = 0; uri nativeuri = tonativeuri(inputurl); string mimetype = resourceapi.getmimetype(nativeuri); cursor cursor = opencursorforurl(nativeuri); try { if (cursor != null && cursor.movetofirst()) { size = resourcesizeforcursor(cursor); long modified = lastmodifieddateforcursor(cursor); if (modified != null) lastmodified = modified.longvalue(); } else { // content providers don't support cursors @ all! cordovaresourceapi.openforreadresult offr = resourceapi.openforread(nativeuri); size = offr.length; } } catch (ioexception e) { throw new filenotfoundexception(); } { if (cursor != null) cursor.close(); } jsonobject metadata = new jsonobject(); try { metadata.put("size", size); metadata.put("type", mimetype); metadata.put("name", name); metadata.put("fullpath", inputurl.path); metadata.put("lastmodifieddate", lastmodified); } catch (jsonexception e) { return null; } return metadata; } protected long lastmodifieddateforcursor(cursor cursor) { int columnindex = cursor.getcolumnindex(mediastore.mediacolumns.date_modified); if (columnindex == -1) { columnindex = cursor.getcolumnindex(documentscontract.document.column_last_modified); } if (columnindex != -1) { string datestr = cursor.getstring(columnindex); if (datestr != null) { return long.parselong(datestr); } } return null; }
Comments
Post a Comment