Save photos to Android Gallery -


i try add bitmap photo took phone gallery in android studio getting error:

failed insert image    java.lang.securityexception: permission denial: writing com.android.providers.media.mediaprovider uri content://media/external/images/media pid=4110, uid=10058 requires android.permission.write_external_storage, or granturipermission() 

i have used in manifest xml:

<uses-permission android:name="android.permission.read_external_storage" android:maxsdkversion="21"/> <uses-permission android:name="android.permission.write_external_storage" android:maxsdkversion="21" /> 

the way save image is:

mediastore.images.media.insertimage(getcontentresolver(), fullbitmap, "name" , "date"); 

i using nexus 5 emulator , android version 5.1.

as @njzk2 pointed out, not use android:maxsdkversion attribute. attribute meant permissions no longer necessary higher api levels. example given in documentation 1 of few reasons should apply attribute:

for example, beginning android 4.4 (api level 19), it's no longer necessary app request write_external_storage permission when app wants write own application-specific directories on external storage (the directories provided getexternalfilesdir()). however, permission required api level 18 , lower.

in case, accessing public directory; do need write_external_storage permission on api levels.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -