I had an app that is working fine in the below version of android while doing the operation on the Android 11 version for gallery and camera capturing pics the app gets crashed. it is showing me an error on the below code. I am doing here getting images from the device and showing in grid view as well as capturing pic and set to the desired location.
protected String doInBackground(String... args) {
String xml = "";
String path = null;
String album = null;
String timestamp = null;
String countPhoto = null;
Uri uriExternal = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Uri uriInternal = android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI;
String[] projection = {MediaStore.MediaColumns.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME, MediaStore.MediaColumns.DATE_MODIFIED };
//It is showing me error on below line of cursor
Cursor cursorExternal = Objects.requireNonNull(getActivity()).getContentResolver().query(uriExternal, projection, "_data IS NOT NULL) GROUP BY (bucket_display_name",
null, null);
Cursor cursorInternal = getActivity().getContentResolver().query(uriInternal, projection, "_data IS NOT NULL) GROUP BY (bucket_display_name",
null, null);
Cursor cursor = new MergeCursor(new Cursor[]{cursorExternal,cursorInternal});
while (cursor.moveToNext()) {
path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA));
album = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.BUCKET_DISPLAY_NAME));
timestamp = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATE_MODIFIED));
if((timestamp == null || timestamp.isEmpty()))
{
timestamp="1111";
}
// System.out.println("Time stamp"+album+timestamp);
countPhoto = Function.getCount(getActivity(), album);
albumList.add(new GalleryGridData(album, path, timestamp, countPhoto,isSelecetd));
}
cursor.close();
return xml;
}
and the error is :
Caused by: android.database.sqlite.SQLiteException: near "GROUP": syntax error (code 1 SQLITE_ERROR): , while compiling: SELECT _data, bucket_display_name, date_modified FROM images WHERE ((is_pending=0) AND (is_trashed=0)) AND ((_data IS NOT NULL) GROUP BY (bucket_display_name))
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:184)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:437)
at android.content.ContentResolver.query(ContentResolver.java:962)
at android.content.ContentResolver.query(ContentResolver.java:890)
at android.content.ContentResolver.query(ContentResolver.java:846)