Search code examples
androidfirebasefirebase-authenticationandroid-glidestorage-access-framework

Glide throwing 'java.lang.SecurityException' while loading profile picture URL from Firebase


I am getting following error message while loading profile picture of a firebase user from firebaseUser.getPhotoUrl() method (Note: Im using Glide to load picture from URI).

Caused by: java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{ccece88 5351:joseph.benton.viqua/u0a122} (pid=5351, uid=10122) requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs

I checked the return vale of firebase.getPhotoUrl() method and its vale is

content://com.android.providers.media.documents/document/image%3A10337

This is my code snippet

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

if(user!=null){
            try {
                Glide.with(context)
                        .load(user.getPhotoUrl())
                        .apply(new RequestOptions()
                                .placeholder(R.drawable.ic_account_circle_white_48dp)
                                .diskCacheStrategy(DiskCacheStrategy.NONE)
                                .skipMemoryCache(true))
                        .into(imgAccount);
            } catch (IOException e) {
                e.printStackTrace();
            }
}

Solution

  • Finally I'm able to find the issue, the issue was related to the profile picture upload module. The uploading module was selecting wrong file type. Uploaded proper image file and above code is working fine as expected.