HBiSoft / PickiT

An Android library that returns real paths from Uri's

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crash on Google Drive File Selection

i140394 opened this issue · comments

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

What version are you using?

Library: 0.1.9
OS: Android 6.0

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

Sure.

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

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

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

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

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

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

to

intent.setType("application/pdf");

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

Yes. It is still crashing.

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).

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

but the dividing is happening on line 93:

publishProgress((int) ((total * 100) / size));

Please add this:

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

here:

and let me know if the size is 0.

Please add this:

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

here:

and let me know if the size is 0.

Please check the above

OK. Sure

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

Thank you.

Please change the entire while loop:

while ((count = bis.read(data)) != -1) {

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.

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.

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.

OK. Thank You.

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.