简体   繁体   中英

ContentResolver invalid column error on Android Q (SDK 29)

Our Android application relies heavily on queries on the ContentResolver to get and manage photos and videos stored on the device. We are aware of the obvious changes in Android Q regarding the DATA fields and the scoped storage. However, we experience some weird issues on our Pixel 2 for queries, that use more complex expressions in the SQL projection. For example we do something like this:

final String[] projection = {MediaStore.MediaColumns._ID,
                                     MediaStore.MediaColumns.DATA,
                                     MediaStore.MediaColumns.MIME_TYPE,
                                     getDateColumn(target, sortMode),
                                     MediaStore.MediaColumns.TITLE,
                                     "rtrim(" + MediaStore.MediaColumns.DATA + ", replace(" +
                                     MediaStore.MediaColumns.DATA + ", '/', '')) as " + COLUMN_DIRECTORY,
                                     "substr(" + MediaStore.MediaColumns.DATA + ", " + "length(rtrim(" +
                                     MediaStore.MediaColumns.DATA + ", replace(" + MediaStore.MediaColumns.DATA +
                                     ", '/', '')) )" + ")" + "as " + COLUMN_FILENAME,
                                     MediaStore.MediaColumns.DISPLAY_NAME,
                                     MediaStore.MediaColumns.DATE_ADDED};

Which used to work absolutely fine up until now. On the latest Android Q version however, we get the following exception for every query that uses projections that are not the pure column names:

2019-09-26 15:54:56.733 30276-30659/? E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #4
    Process: xxxx, PID: 30276
    java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$4.done(AsyncTask.java:399)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: java.lang.IllegalArgumentException: Invalid column rtrim(_data, replace(_data, '/', '')) as directory
        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)
        ...

Are these kind of projections forbidden now? Or are we missing something? Thanks in advance!

you can't access anymore to DATA column

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM