Scoped Storage 在安卓 10.0 中引入。

huangapple go评论78阅读模式
英文:

Scoped Storage android 10.0

问题

Crash is here......

android.database.sqlite.SQLiteException: near "GROUP": syntax error (Sqlite code 1 SQLITE_ERROR): , while compiling: SELECT _id, bucket_display_name, bucket_id, _id, orientation FROM images WHERE ((is_pending=0) AND (is_trashed=0) AND (volume_name IN ( 'external_primary' ))) AND ((1) GROUP BY 1,(2)) ORDER BY date_modified DESC, (OS error - 2:No such file or directory)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:184)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
    at android.content.ContentResolver.query(ContentResolver.java:955)
    at android.content.ContentResolver.query(ContentResolver.java:891)
    at android.content.ContentResolver.query(ContentResolver.java:840)

Below is method to show all folders or album of images.

private boolean logGalleryFolders() {
    this.albumList = new ArrayList<>();
    List<Integer> bucketIdList = new ArrayList<>();
    Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id", "bucket_display_name", "bucket_id", "_id", "orientation"}, "1) GROUP BY 1,(2", null, "date_modified DESC");

    List<GridViewItem> items;
    int i;
    if (cur == null || !cur.moveToFirst()) {
        items = new ArrayList<>();
        for (i = 0; i < this.albumList.size(); i++) {
            items.add(new GridViewItem(this.activity, this.albumList.get(i).name, BuildConfig.FLAVOR + this.albumList.get(i).imageIdList.size(), true, this.albumList.get(i).imageIdForThumb, this.albumList.get(i).orientationList.get(0).intValue()));
        }
        this.albumList.add(new Album());
        this.albumList.get(this.albumList.size() - 1).gridItems = items;
        for (i = 0; i < this.albumList.size() - 1; i++) {
            this.albumList.get(i).gridItems = createGridItemsOnClick(i);
        }

        if (cur != null) {
            cur.close();
        }
        return true;
    }
    int bucketColumn = cur.getColumnIndex("bucket_display_name");
    int bucketId = cur.getColumnIndex("bucket_id");
    int imageId = cur.getColumnIndex("_id");
    int orientationColumnIndex = cur.getColumnIndex("orientation");
    do {
        Album album = new Album();
        int id = cur.getInt(bucketId);
        album.ID = id;
        if (bucketIdList.contains(id)) {
            Album albumFromList = this.albumList.get(bucketIdList.indexOf(album.ID));
            albumFromList.imageIdList.add(cur.getLong(imageId));
            albumFromList.orientationList.add(cur.getInt(orientationColumnIndex));
        } else {
            String bucket = cur.getString(bucketColumn);
            bucketIdList.add(id);
            album.name = bucket;
            album.imageIdForThumb = cur.getLong(imageId);
            album.imageIdList.add(album.imageIdForThumb);
            this.albumList.add(album);
            album.orientationList.add(cur.getInt(orientationColumnIndex));
        }
    } while (cur.moveToNext());
    items = new ArrayList<>();
    for (i = 0; i < this.albumList.size(); i++) {
        items.add(new GridViewItem(this.activity, this.albumList.get(i).name, BuildConfig.FLAVOR + this.albumList.get(i).imageIdList.size(), true, this.albumList.get(i).imageIdForThumb, this.albumList.get(i).orientationList.get(0).intValue()));
    }
    this.albumList.add(new Album());
    this.albumList.get(this.albumList.size() - 1).gridItems = items;
    for (i = 0; i < this.albumList.size() - 1; i++) {
        this.albumList.get(i).gridItems = createGridItemsOnClick(i);
    }
    cur.close();
    return true;
}

Below is crash line......

Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id", "bucket_display_name", "bucket_id", "_id", "orientation"}, "1) GROUP BY 1,(2", null, "date_modified DESC");
英文:

Crash is here......

android.database.sqlite.SQLiteException: near "GROUP": syntax error (Sqlite code 1 SQLITE_ERROR): , while compiling: SELECT _id, bucket_display_name, bucket_id, _id, orientation FROM images WHERE ((is_pending=0) AND (is_trashed=0) AND (volume_name IN ( 'external_primary' ))) AND ((1) GROUP BY 1,(2)) ORDER BY date_modified DESC, (OS error - 2:No such file or directory)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:184)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:423)
at android.content.ContentResolver.query(ContentResolver.java:955)
at android.content.ContentResolver.query(ContentResolver.java:891)
at android.content.ContentResolver.query(ContentResolver.java:840)

Below is method to show all folders or album of images.

private boolean logGalleryFolders() {
this.albumList = new ArrayList&lt;&gt;();
List&lt;Integer&gt; bucketIdList = new ArrayList&lt;&gt;();
Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{&quot;_id&quot;, &quot;bucket_display_name&quot;, &quot;bucket_id&quot;, &quot;_id&quot;, &quot;orientation&quot;}, &quot;1) GROUP BY 1,(2&quot;, null, &quot;date_modified DESC&quot;);
List&lt;GridViewItem&gt; items;
int i;
if (cur == null || !cur.moveToFirst()) {
items = new ArrayList&lt;&gt;();
for (i = 0; i &lt; this.albumList.size(); i++) {
items.add(new GridViewItem(this.activity, this.albumList.get(i).name, BuildConfig.FLAVOR + this.albumList.get(i).imageIdList.size(), true, this.albumList.get(i).imageIdForThumb, this.albumList.get(i).orientationList.get(0).intValue()));
}
this.albumList.add(new Album());
this.albumList.get(this.albumList.size() - 1).gridItems = items;
for (i = 0; i &lt; this.albumList.size() - 1; i++) {
this.albumList.get(i).gridItems = createGridItemsOnClick(i);
}
if (cur != null) {
cur.close();
}
return true;
}
int bucketColumn = cur.getColumnIndex(&quot;bucket_display_name&quot;);
int bucketId = cur.getColumnIndex(&quot;bucket_id&quot;);
int imageId = cur.getColumnIndex(&quot;_id&quot;);
int orientationColumnIndex = cur.getColumnIndex(&quot;orientation&quot;);
do {
Album album = new Album();
int id = cur.getInt(bucketId);
album.ID = id;
if (bucketIdList.contains(id)) {
Album albumFromList = this.albumList.get(bucketIdList.indexOf(album.ID));
albumFromList.imageIdList.add(cur.getLong(imageId));
albumFromList.orientationList.add(cur.getInt(orientationColumnIndex));
} else {
String bucket = cur.getString(bucketColumn);
bucketIdList.add(id);
album.name = bucket;
album.imageIdForThumb = cur.getLong(imageId);
album.imageIdList.add(album.imageIdForThumb);
this.albumList.add(album);
album.orientationList.add(cur.getInt(orientationColumnIndex));
}
} while (cur.moveToNext());
items = new ArrayList&lt;&gt;();
for (i = 0; i &lt; this.albumList.size(); i++) {
items.add(new GridViewItem(this.activity, this.albumList.get(i).name, BuildConfig.FLAVOR + this.albumList.get(i).imageIdList.size(), true, this.albumList.get(i).imageIdForThumb, this.albumList.get(i).orientationList.get(0).intValue()));
}
this.albumList.add(new Album());
this.albumList.get(this.albumList.size() - 1).gridItems = items;
for (i = 0; i &lt; this.albumList.size() - 1; i++) {
this.albumList.get(i).gridItems = createGridItemsOnClick(i);
}
cur.close();
return true;
}

Below is crash line......

Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{&quot;_id&quot;, &quot;bucket_display_name&quot;, &quot;bucket_id&quot;, &quot;_id&quot;, &quot;orientation&quot;}, &quot;1) GROUP BY 1,(2&quot;, null, &quot;date_modified DESC&quot;);

答案1

得分: 1

只需将查询更改为以下内容:

 Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{&quot;_id&quot;, &quot;bucket_display_name&quot;, &quot;bucket_id&quot;, &quot;_id&quot;, &quot;orientation&quot;}, &quot;1) GROUP BY 1,(2&quot;, null, &quot;date_modified DESC&quot;);

Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{&quot;_id&quot;, &quot;bucket_display_name&quot;, &quot;bucket_id&quot;, &quot;_id&quot;, &quot;orientation&quot;}, null, null, &quot;date_modified DESC&quot;);
英文:

Just change the query like below:

From

 Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{&quot;_id&quot;, &quot;bucket_display_name&quot;, &quot;bucket_id&quot;, &quot;_id&quot;, &quot;orientation&quot;}, &quot;1) GROUP BY 1,(2&quot;, null, &quot;date_modified DESC&quot;);

To

Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{&quot;_id&quot;, &quot;bucket_display_name&quot;, &quot;bucket_id&quot;, &quot;_id&quot;, &quot;orientation&quot;}, null, null, &quot;date_modified DESC&quot;);

答案2

得分: 0

您的 GROUP BY 出现在 AND 内导致了问题。请将您的 query 修改如下:

SELECT
  _id,
  bucket_display_name,
  bucket_id,
  _id,
  orientation
FROM
  images
WHERE
  (
    (is_pending = 0)
    AND (is_trashed = 0)
    AND (volume_name IN ('external_primary'))
  )
  AND ((1))
GROUP BY
  1, 2
ORDER BY
  date_modified DESC
英文:

Your GROUP BY comes inside the And makes the issue. Please change your query as below:

SELECT
_id,
bucket_display_name,
bucket_id,
_id,
orientation
FROM
images
WHERE
(
(is_pending = 0)
AND (is_trashed = 0)
AND (volume_name IN (&#39;external_primary&#39;))
)
AND ((1))
GROUP BY
1,(2)
ORDER BY
date_modified DESC

huangapple
  • 本文由 发表于 2020年9月16日 12:34:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/63913196.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定