HBiSoft / PickiT

An Android library that returns real paths from Uri's
MIT License
292 stars 54 forks source link

Crash on Google Drive File Selection #14

Closed i140394 closed 4 years ago

i140394 commented 4 years ago

My App is crashing when I have selected a file from Google Drive. PickiT: 0.1.9 Mobile: Android Version: 6.0

Screen Shot 2020-02-21 at 4 35 27 PM

HBiSoft commented 4 years ago

What version are you using?

i140394 commented 4 years ago

Library: 0.1.9 OS: Android 6.0

HBiSoft commented 4 years ago

Can you send me a link to a file I can test with? The size should not be zero.

i140394 commented 4 years ago

Sure.

i140394 commented 4 years ago

It's only happening when I am selecting drive file from Recents screen.

i140394 commented 4 years ago

File Link: https://drive.google.com/open?id=1uNzJ5p-ZpNs0Ii-Yc5zEpYAwWgvJb5PGzcOJajLxTNc

HBiSoft commented 4 years ago

Can you please share the uri when selecting it from Google Drive and when you select it from Recents?

i140394 commented 4 years ago

Ok. It is crashing for Google sheet/doc etc files from Recents and Drive also. I will share you the Uris shortly.

i140394 commented 4 years ago

For your reference: I think this is the same issue as below one DownloadAsyncTask divide by zero #9

i140394 commented 4 years ago

From Drive: content://com.google.android.apps.docs.storage/document/acc%3D9%3Bdoc%3Dencoded%3DJnO56ZsvMKX3juRDYo4DF7Xyod10TSNi6bERrFPTBkeJeXMci%2FlQaQ%3D%3D From Recents: content://com.google.android.apps.docs.storage/document/acc%3D9%3Bdoc%3Dencoded%3DJnO56ZsvMKX3juRDYo4DF7Xyod10TSNi6bERrFPTBkeJeXMci%2FlQaQ%3D%3D

HBiSoft commented 4 years ago

I tested on my device with the demo application and I do not see the crash, please download the project and change the following:

https://github.com/HBiSoft/PickiT/blob/c3cb420697a04a1f2c3909c0cf9fa9635bf024ef/app/src/main/java/com/hbisoft/pickitexample/MainActivity.java#L92

to

intent.setType("application/pdf");

The run that on your device and see if you still get the error.

i140394 commented 4 years ago

Yes. It is still crashing.

HBiSoft commented 4 years ago

It doesn't make sense, here is a screenshot when selecting the file you sent me from Google Drive:

Screenshot_20200221-145403_PickiT example

I will change the code to check if the file size is not 0 (which it should not be, but I will do it anyway).

HBiSoft commented 4 years ago

The other thing I do not understand is that your log is pointing to:

https://github.com/HBiSoft/PickiT/blob/c3cb420697a04a1f2c3909c0cf9fa9635bf024ef/pickit/src/main/java/com/hbisoft/pickit/DownloadAsyncTask.java#L98

but the dividing is happening on line 93:

https://github.com/HBiSoft/PickiT/blob/c3cb420697a04a1f2c3909c0cf9fa9635bf024ef/pickit/src/main/java/com/hbisoft/pickit/DownloadAsyncTask.java#L93

HBiSoft commented 4 years ago

Please add this:

Log.e("Size =". ""+size);

here:

https://github.com/HBiSoft/PickiT/blob/c3cb420697a04a1f2c3909c0cf9fa9635bf024ef/pickit/src/main/java/com/hbisoft/pickit/DownloadAsyncTask.java#L78

and let me know if the size is 0.

i140394 commented 4 years ago

Hope this will help. https://drive.google.com/open?id=171_Kg1UQYlwFKiLYBLz8uGmK9oRh2KG0

HBiSoft commented 4 years ago

Please add this:

Log.e("Size =". ""+size);

here:

https://github.com/HBiSoft/PickiT/blob/c3cb420697a04a1f2c3909c0cf9fa9635bf024ef/pickit/src/main/java/com/hbisoft/pickit/DownloadAsyncTask.java#L78

and let me know if the size is 0.

Please check the above

i140394 commented 4 years ago

OK. Sure

i140394 commented 4 years ago

Yes. Size is zero. I have added Log statement at line number 79.

Screen Shot 2020-02-24 at 11 17 18 AM

Screen Shot 2020-02-24 at 11 17 38 AM

HBiSoft commented 4 years ago

Thank you.

Please change the entire while loop:

https://github.com/HBiSoft/PickiT/blob/c3cb420697a04a1f2c3909c0cf9fa9635bf024ef/pickit/src/main/java/com/hbisoft/pickit/DownloadAsyncTask.java#L89

to the following:

while ((count = bis.read(data)) != -1) {
    if (!isCancelled()) {
        total += count;
        if (size != -1) {
            try {
                publishProgress((int) ((total * 100) / size));
            }catch(Exception e){
                Log.i("PickiT -", "File size is less than 1");
                publishProgress(0);
            }
        }
        fos.write(data, 0, count);
    }
}

Let me know if the crash goes away and I will update the library.

i140394 commented 4 years ago

The crash is gone. But I was getting file size as 0. Is it because size is int field? And my file size is less than 1MB. Is that it? I have some test data in my google sheet.

HBiSoft commented 4 years ago

Yes, the problem is that your file size is 0.23MB for example, and it gets rounded to 0, thus the error. I'm busy updating the library.

i140394 commented 4 years ago

OK. Thank You.

HBiSoft commented 4 years ago

This is fixed in 0.1.10. You can test it with the demo application if you would like.

Please test it and close the issue if it is fixed.