In an Android application,
And Android 10 regarding Scoped Storage,
Picasso is able to truly display an image with the Uri of an image
And it does not require any permission even if the versin of Android is 10
But when I try to use openInputStream
, an error occurs which indicates permission is not granted
I wonder how Picasso can display the image without any permission but opening stream requires permission
The code is as following:
Picasso.with(mContext).load(mUri).resize(200, 200).into(mImageButton);
InputStream mInputStream;
try
{
mInputStream = mContext.getContentResolver().openInputStream(mUri);
} catch (Exception e) {
e.printStackTrace();
}
And the error is as following:
java.lang.SecurityException: Permission Denial: reading com.miui.gallery.provider.GalleryOpenProvider uri content://com.miui.gallery.open/raw/storage/emulated/0/Download/MellatMobileBank_Android.apk/icons/jar-gray.png from pid=2300, uid=10251 requires the provider be exported, or grantUriPermission()
Then, how can I have the stream of the image without granting permission?
Edit:
I did a test in onActivityResult
where the image result could be retrieved from to see if the openInputStream
works there or not
The code is as following:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.Uri_M) {
if (resultCode == RESULT_OK) {
Uri_M = data.getData();
Uri_M_String = Uri_M.toString();
mInputStream = getApplicationContext().getContentResolver().openInputStream(Uri_M);
Above code works fine while the following code has the same previous error (permission issue):
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Constants.Uri_M) {
if (resultCode == RESULT_OK) {
Uri_M = data.getData();
Uri_M_String = Uri_M.toString();
Uri b = Uri.parse(Uri.decode(Uri_M_String));
mInputStream = getApplicationContext().getContentResolver().openInputStream(b);
The point is Picasso is working fine with Uri_M_String but for openInputStream
I first convert the Uri_M_String
to Uri_M
as following:
Uri Uri_M = Uri.parse(Uri.decode(Uri_M_String));
And then:
mInputStream = getApplicationContext().getContentResolver().openInputStream(Uri_M);
Which results in the error
So the problem is the conversion I'm doing to get the Uri from Uri string
But how can I reach the true Uri from its Uri string?