0

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)
               
  • done ...!! please help me ... – Phil Winston Jan 18 '21 at 10:13
  • sorry, I am new to StackOverflow....thank you for correcting me...now is it fine? then please kindly help me. – Phil Winston Jan 18 '21 at 11:28
  • Get rid of `cursorInternal` and `cursorExternal`. In other words, stop assuming the structure of database tables that you did not create. – CommonsWare Jan 18 '21 at 12:03
  • @CommonsWare thank you for the comment sir ...please guide me ..while I searched for the issue some says GroupBy clause will no longer work in android 11 – Phil Winston Jan 18 '21 at 14:10
  • It was never reliable in the first place. Device manufacturers can change the internal implementation of Android however they see fit. – CommonsWare Jan 18 '21 at 14:13
  • then what would be the solution for this ...please kindly know me ... I had stuck to this error for a week. – Phil Winston Jan 18 '21 at 14:40
  • Start with catching the SQLiteException. Then your app will no longer crash. And read stackoverflow pages tagged `mediastore`. – blackapps Jan 18 '21 at 15:43
  • `Crashlytics android 11 device crash on capturing photo and opening gallery` Well that is not true and very confusing. Think about a better subject please. – blackapps Jan 18 '21 at 15:45

0 Answers0