App crashes due to java.lang.SecurityException

前端 未结 5 918
甜味超标
甜味超标 2021-01-17 01:16

I am working on the project of capturing photos or picking images from gallery and show it in the recycler view, the app is working good in Android-lollipop but crashes in m

5条回答
  •  囚心锁ツ
    2021-01-17 01:55

    you will need this permission too.

    
    

    and for writing data to storage you will need runtime permission
    make request

     ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                REQUEST_WRITE_STORAGE);
    

    and check if user granted or decline to the permission request.

         @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String permissions[], int[] grantResults) {
        switch (requestCode) {
            case REQUEST_WRITE_STORAGE: {
    
                if (grantResults.length == 0
                        || grantResults[0] !=
                        PackageManager.PERMISSION_GRANTED) {
    
                    Log.i(TAG, "Permission has been denied by user");
    
                } else {
    
                    Log.i(TAG, "Permission has been granted by user");
    
                }
                return;
            }
        }
    }
    

提交回复
热议问题