Gödel77
Gödel77

Reputation: 839

Sdcard Content not visible in DDMS File Explorer Android 6.0

Android 6.0 has changed its way to manage sdcard-mounting and that doesn't let show right.

Until 5.x we could access to the SDCard Contents via DDMS Perspective (Eclipse) under the hierarchy

/mnt/shell/...

and now according Documentation under

/sdcard/

I can't see any content of this directory under DDMS but in the PC or other Apps (like Astro).

What should I set in Eclipse(DDMS) in order to be able to see that content?

Upvotes: 1

Views: 1770

Answers (1)

Maksym Kalin
Maksym Kalin

Reputation: 1713

Starting Android 6.0, third-party apps have no ability to see SDCard content.

In Android 6.0, third-party apps don’t have access to the sdcard_r and sdcard_rw GIDs. Instead, access is controlled by mounting only the appropriate runtime view in place for that app. Cross-user interactions are blocked using the everybody GID.

https://source.android.com/devices/storage/

As additional information, Android 6.0 introduces Adoptable Storage and Runtime Permissions which impose restrictions on the interaction with a storage of device.

Hope it helps you.

Update

Regarding how get access to a file from DDMS to Android 6.0. This action is not allowed. If you need to get access to file from your app you can use this source code example :

   @Override
   protected void onCreate(Bundle savedInstanceState) {

        mPermissions = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE };
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
           boolean isAllow = ContextCompat.checkSelfPermission(this, mPermissions[0]) == PackageManager.PERMISSION_GRANTED;
           if (!isAllow) {
              if (shouldShowRequestPermissionRationale(mPermissions[0])) {
                 // There is you need to display confirmation dialog about why you need to get this permission. 
                 if (confirm("You need to copy database to  device's storage") == YES) {
                     requestPermissions(mPermissions, REQUEST_CODE_ASK_PERMISSIONS)   
                  } else {
                     // User does not agree with your requirements
                     // You should decide how the app will work in this case.
                     message("You can't use this app!");
                     finish();
                  }
                  return;
              }
              requestPermissions(mPermissions, REQUEST_CODE_ASK_PERMISSIONS);
           }

        } else {
          runTheApp();
        }
   }

 @Override
 public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
            switch (requestCode) {
                case REQUEST_CODE_ASK_PERMISSIONS:
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                            runTheApp();
                        } else {
                            message("You can't use this app!")
                        }
                    }
                break;
                case REJECT_CODE_PERMISSIONS:
                    break;
                default:
                    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
            }
    }

Upvotes: 1

Related Questions