vansikrishna / Multimager

Multi Image Picker and Multi Image Capture Library
73 stars 22 forks source link

Issue now arriving on api22( 5.1) #7

Open PrafulAnand opened 7 years ago

PrafulAnand commented 7 years ago

I am testing my app against different version beacause I have to launch it..Now i am able to open the camera and as soon as I click the photo my app crashes.....Not able to fix the issue..error in android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0 at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426) at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136) at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50) at android.database.CursorWrapper.getString(CursorWrapper.java:114) at com.vlk.multimager.activities.CameraFragment.getImageRealPathFromURI(CameraFragment.java:578) at com.vlk.multimager.activities.CameraFragment.getOutputMediaFile(CameraFragment.java:588) at com.vlk.multimager.activities.CameraFragment$5.onPictureTaken(CameraFragment.java:673) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1102) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5354) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:947) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)

PrafulAnand commented 7 years ago

Sir I tested multimager apk directly on my device 5.1 api 22(lyf mobile phone flame seven) the same issue persists so I think something is really messing up the camera fragment most probably I guess.... When the multi capture button is clicked the camera opens but as soon as I click the photo the app crashes and redirects to main screen.... Not able to solve it

vansikrishna commented 7 years ago

Almost unable to replicate this too. I do not have a real device with version 5.1 exactly. I have tested on a device with version 5.1.1 and all emulators but its all working good. Probably the reason is mentioned in the crash report mentioned above. I have added a try catch for a fail case. I believe the issue is with the "fileUri" using which we are trying to get the real path of the image captured in the method "getImageRealPathFromURI()". I have provided logs at various places to check the value of "fileUri" object. Else you can debug to check its value. Please upgrade to version 1.0.6 after some time.

PrafulAnand commented 7 years ago

OK so how to get around this problem.... After checking the logs Exception in photoCallback java.io.FileNotFoundException: : open failed: ENOENT (No such file or directory) at libcore.io.IoBridge.open(IoBridge.java:456) at java.io.FileOutputStream.(FileOutputStream.java:87) at java.io.FileOutputStream.(FileOutputStream.java:127) at java.io.FileOutputStream.(FileOutputStream.java:116) at com.vlk.multimager.activities.CameraFragment$SavePhotoTask.doInBackground(CameraFragment.java:711) at com.vlk.multimager.activities.CameraFragment$SavePhotoTask.doInBackground(CameraFragment.java:696) at android.os.AsyncTask$2.call(AsyncTask.java:292) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory) at libcore.io.Posix.open(Native Method) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186) at libcore.io.IoBridge.open(IoBridge.java:442) at java.io.FileOutputStream.(FileOutputStream.java:87)  at java.io.FileOutputStream.(FileOutputStream.java:127)  at java.io.FileOutputStream.(FileOutputStream.java:116)  at com.vlk.multimager.activities.CameraFragment$SavePhotoTask.doInBackground(CameraFragment.java:711)  at com.vlk.multimager.activities.CameraFragment$SavePhotoTask.doInBackground(CameraFragment.java:696)  at android.os.AsyncTask$2.call(AsyncTask.java:292)  at java.util.concurrent.FutureTask.run(FutureTask.java:237)  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)  at java.lang.Thread.run(Thread.java:818) 

this error in my device running on 5.1 api 22 after you updated the repo....( I am using 1.0.6 multimager version)

vansikrishna commented 7 years ago

That is obvious. If you can check the source code for CameraFragment class, the issue is with the getImageRealPathFromURI() method. We are trying to query the full image path from the newly created fileUri but in your device the query returns zero results. Hence a blank path is returned which cannot be saved by the SavePhotoTask async class.

vansikrishna commented 7 years ago

I would suggest you should write a small application first to replicate the process of inserting a image data into MediaStore.Images table and querying it back using the fileUri. Simply put, please check if the getOutputMediaFile() method produces a valid File object for you. If this works in your device, then the library should work too.

PrafulAnand commented 7 years ago

Could you suggest some more detail I am not able to get around this problem why it's arriving in this 5.1 api only...

vansikrishna commented 7 years ago

I have tested in some other devices running 5.1 and 5.1.1 too but it is working good there. Only in the case of Lyf phones running 5.1 i am seeing this error. I have tested here with a Lyf phone model number LS 4005 showcased as Flame. Unfortunately it has no adb drivers to debug using the device. But as i stated, the getOutputMediaFile() method is creating the problem. The approach used here is a very standard one, that i have used for most of my applications(finally put through as this library).

vansikrishna commented 7 years ago

On a personal note @PrafulAnand , you can do one thing. While creating the ContentValues object for inserting a media record, you can input the full path too along with title. And finally use it to create file object. For example the getOutputMediaFile() method can be changed to as following: private File getOutputMediaFile(){ String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmmss").format(new Date()); ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, timeStamp + ".jpg"); File imageFile = new File(Environment.getExternalStorageDirectory(), timeStamp + ".jpg"); values.put(MediaStore.Images.Media.DATA, imageFile.getPath()); Uri fileUri = getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); return imageFile; }