Permission dialog is not shown for WRITE_EXTERNAL_STORAGE

这一生的挚爱 提交于 2019-12-11 16:56:30

问题


I want to download a file using DownloadManager. And DownloadManager wants to WRITE_EXTERNAL_STORAGE permission. I have included the WRITE_EXTERNAL_STORAGE permission in AndroidManifest.xml. Furthermore, I try to take this permission on runtime.

onRequestPermissionsResult callback is called immediately after the request permission. The request permission popup didn't display.

However, the value of the grantResult[0] on the onRequestPermissionsResult is PERMISSION_DENIED. But THE PERMISSION POPUP ISN'T EVEN SHOWN.

I check the permission like this:

public  boolean isStoragePermissionGranted() {
    if (Build.VERSION.SDK_INT >= 23) {
        if (checkSelfPermission(getContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
                == PackageManager.PERMISSION_GRANTED) {
            Log.v(TAG,"Permission is granted");
            return true;
        } else {

            Log.v(TAG,"Permission is revoked");
            ActivityCompat.requestPermissions(getActivity(), new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_PERMISSION_REQUEST_CODE);
            return false;
        }
    }
    else {
        Log.v(TAG,"Permission is granted");
        return true;
    }
}

And this is callback of the permission request:

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
        case WRITE_EXTERNAL_PERMISSION_REQUEST_CODE: {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                downloadFile();
            }
            break;
        }
    }
}

When I have tried for READ_EXTERNAL_STORAGE permission, I could take that permission but it didn't work for WRITE_EXTERNAL_STORAGE permission.

Also, I have tried @MetaSnarf's solution. But nothing has changed.

Have you any idea about this situation?


回答1:


One of your dependency can cause that problem. You can replace permission in your manifest.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />


来源:https://stackoverflow.com/questions/53192161/permission-dialog-is-not-shown-for-write-external-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!