英文:
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<>();
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");
答案1
得分: 1
只需将查询更改为以下内容:
从
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");
到
Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id", "bucket_display_name", "bucket_id", "_id", "orientation"}, null, null, "date_modified DESC");
英文:
Just change the query like below:
From
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");
To
Cursor cur = this.context.getContentResolver().query(Media.EXTERNAL_CONTENT_URI, new String[]{"_id", "bucket_display_name", "bucket_id", "_id", "orientation"}, null, null, "date_modified DESC");
答案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 ('external_primary'))
)
AND ((1))
GROUP BY
1,(2)
ORDER BY
date_modified DESC
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论