So my app is using Firebase to store user data which includes an avatar. I have the user select an image from the gallery and then I set my ImageView to the Uri of that file, which works fine.
When I then push that Uri.toString(); to Firebase and then try to read it again(in order to have the Avatar persist across sessions), I get a "resolveUri failed on bad bitmap uri" error.
This is the code from where I am setting the image chosen from the gallery originally:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == 1 && intent != null && resultCode == Activity.RESULT_OK) {
Uri uri = intent.getData();
Firebase usersRef = firebase.child("users").child("dummyUID").child("avatar");
usersRef.setValue(uri.getPath());
avatarIV.setImageURI(uri);
} else {
Log.d("Status:" , "Photo Picker Cancelled");
}
}
And then this is the code I am using to try and pull that same Image Uri from Firebase, which fails:
avatarRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Uri uri = Uri.parse(dataSnapshot.getValue().toString());
avatarIV.setImageURI(uri);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
I have put in log statements to figure out what could be different with the path, however it is the exact same in both locations.
Here are the permissions I have in my manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_DOCUMENTS"/>
I have tried almost every fix suggested in other threads that I could find to no avail. I figured this was a slightly different case scenario as I was reading the Uri back from Firebase.
Thanks in advance, Jeff