Android Q(SDK 29)上的ContentResolver无效列错误

时间:2019-09-26 13:59:35

标签: android sql android-sqlite android-contentresolver android-10.0

我们的Android应用程序严重依赖ContentResolver上的查询来获取和管理存储在设备上的照片和视频。我们知道Android Q中有关DATA字段和范围存储的明显变化。但是,我们在Pixel 2上遇到一些奇怪的查询问题,这些问题在SQL投影中使用更复杂的表达式。例如,我们做这样的事情:

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};

直到现在,以前哪个都可以正常工作。但是,在最新的Android Q版本上,对于使用非纯列名投影的每个查询,我们都会收到以下异常:

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

现在禁止这种预测吗?还是我们错过了什么? 预先感谢!

1 个答案:

答案 0 :(得分:1)

您无法再访问DATA