Following the documentation
I tried querying ContentResolver
to get the file size, like this:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == video_request_code) {
if (resultCode == RESULT_OK) {
Uri uri = data.getData();
Cursor cur = getContentResolver().query(uri, null, null, null, null);
try {
if (cur != null && cur.moveToFirst()){
if (uri.getScheme() != null){
if (uri.getScheme().equals("content")) {
int sizeIndex = cur.getColumnIndex(OpenableColumns.SIZE);
Log.e("size", ""+cur.getLong(sizeIndex));
}else if (uri.getScheme().equals("file")) {
File ff = new File(uri.getPath());
Log.e("size", ""+ff.length());
}
}
}
}catch (Exception e){
e.printStackTrace();
}
finally {
if (cur != null)
cur.close();
}
}
}
}
Then I get the following error:
java.lang.IllegalArgumentException: Invalid column latitude
at android.app.ActivityThread.deliverResults(ActivityThread.java:4845)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4886)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.IllegalArgumentException: Invalid column latitude
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:170)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
at android.content.ContentResolver.query(ContentResolver.java:944)
at android.content.ContentResolver.query(ContentResolver.java:880)
at android.content.ContentResolver.query(ContentResolver.java:836)
at com.my.package.MainActivity.onActivityResult(MainActivity.java:146)
...
The crash is pointing to Cursor cur = getContentResolver().query(uri, null, null, null, null);
, but as you can see, I'm not querying the latitude column. In fact, at the time of the crash, I have not queried any column.
I could only reproduce this when selecting a file from Google Photo on a device running Android 10.
My Question:
Why is this happening and how can I overcome it?
Edit:
I tried passing the projection of the columns. To test, I passed the following:
String[] projection = {OpenableColumns.SIZE, OpenableColumns.DISPLAY_NAME};
Cursor cur = getContentResolver().query(uri, projection, null, null, null);
But I still get the same error.
See Question&Answers more detail:
os