Search code examples
androiduniversal-image-loaderandroid-6.0-marshmallow

UIL and android.permission.WRITE_EXTERNAL_STORAGE in Android – Marshmallow


After adding UIL to my project, I also add permissions:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

But for android project with targetSdkVersion="23" (marshmallow) I need to check some "dangerous" permission ( such as WRITE_EXTERNAL_STORAGE ) before use.

For example:

if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Log.v(TAG,"Permission is granted");
            return true;
}

But how can I check it? I dont know where UIL use it.

Maybe I misunderstanding or miss something from documentation. Any help would be greatly appreciated.


Solution

  • But how can I check it?

    Use that code, in your own activity or fragment, to check for the permission, before you try using anything from UIL.

    Unless the library that you use happens to have activities or fragments, and therefore might be able to requestPermissions() itself, you have to requestPermissions() before using the library, for any dangerous permissions required by that library.

    As you note, you have no idea where UIL uses those permissions, and even if you knew for today's UIL, you might not know where UIL uses it tomorrow. Hence, you have to check for, and request if needed, the permissions before doing anything with UIL.