0

How do I create folder in INTERNAL STORAGE and save bitmap image in folder on Android marshmallow. I wanted to know particularly in Marshmallow... And I have given all the permission in manifest file. Please help me out to solve this problem..

2 Answers2

0

Ref: Make directory in android

Ref: How to check Grants Permissions at Run-Time?

I just found my need we can check if the permission is granted by :

checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)

Request permissions if necessary

if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                100);

        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant

        return;
    }
Handle the permissions request response
@Override
public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
    switch (requestCode) {
        case 100: {
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! do the
                // calendar task you need to do.

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'switch' lines to check for other
        // permissions this app might request
    }
}

Create Folder Like

File directory = new File(Environment.getExternalStorageDirectory()+File.separator+"images");

directory.mkdirs();

Let me know if this works for you!

You will also need the following line in your AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Ashvin solanki
  • 4,200
  • 2
  • 18
  • 58
0

In particularly Marshmallow version, Permission are need to be taken Programatically. Following is the sample code to read external storage.

ActivityCompat.requestPermissions(MainActivity.this,
                new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                PERMISSION_CODE);

In method onResultPermissionsRequest()

@Override
public void onRequestPermissionsResult(int requestCode,
                                   String permissions[], int[] grantResults) {
   if(requestCode == PERMISSION_CODE){
         if(grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED){

                //Permission granted 
          }
          else{
               //Permission Not granted
          }

   }

}

Hope write similar code for various different permission. Hope this should work. In case this didn't work one thing is sure in Marshmallow need to take permissions dynamically.

Abhishek Borikar
  • 319
  • 1
  • 4
  • 14