hidrodixtion / Example-Retrofit-Image-Upload

Example For Simple Image Upload in Android by Using Retrofit 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failure delivering result ResultInfo

hahn opened this issue · comments

when pick a picture, got error like this. need new permission

FATAL EXCEPTION: main
Process: id.web.hn.belajaruploadfile, PID: 29075
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://media/external/images/media/64 }} to activity {id.web.hn.belajaruploadfile/id.web.hn.belajaruploadfile.MainActivity}: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/64 from pid=29075, uid=10042 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

add this permission in your manifest
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE”/>
and in your code add this

if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE)
        != PackageManager.PERMISSION_GRANTED) {
    // Should we show an explanation?
    if (shouldShowRequestPermissionRationale(
            Manifest.permission.READ_EXTERNAL_STORAGE)) {
        // Explain to the user why we need to read the contacts
    }
    requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
            MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);

    // MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE is an
    // app-defined int constant that should be quite unique

    return;
}

yes, i did that. thanks for the example :D