Sdcard 内容在 DDMS 文件资源管理器中不可见 Android 6.0
Sdcard Content not visible in DDMS File Explorer Android 6.0
Android 6.0 已经改变了管理 sdcard 挂载的方式,这使得显示不正确。
直到 5.x 我们可以通过层次结构下的 DDMS Perspective (Eclipse) 访问 SDCard 内容
/mnt/shell/...
现在根据 Documentation
/sdcard/
我在 DDMS 下看不到这个目录的任何内容,但在 PC 或其他应用程序(如 Astro)中。
我应该在 Eclipse(DDMS) 中设置什么才能看到该内容?
从 Android 6.0 开始,第三方应用无法查看 SDCard 内容。
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/
作为附加信息,Android 6.0 引入了 Adoptable Storage and Runtime Permissions,它对与设备存储的交互施加了限制。
希望对你有帮助。
更新
关于如何从 DDMS 访问文件到 Android 6.0。不允许执行此操作。如果您需要从您的应用程序访问文件,您可以使用此源代码示例:
@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);
}
}
Android 6.0 已经改变了管理 sdcard 挂载的方式,这使得显示不正确。
直到 5.x 我们可以通过层次结构下的 DDMS Perspective (Eclipse) 访问 SDCard 内容
/mnt/shell/...
现在根据 Documentation
/sdcard/
我在 DDMS 下看不到这个目录的任何内容,但在 PC 或其他应用程序(如 Astro)中。
我应该在 Eclipse(DDMS) 中设置什么才能看到该内容?
从 Android 6.0 开始,第三方应用无法查看 SDCard 内容。
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/
作为附加信息,Android 6.0 引入了 Adoptable Storage and Runtime Permissions,它对与设备存储的交互施加了限制。
希望对你有帮助。
更新
关于如何从 DDMS 访问文件到 Android 6.0。不允许执行此操作。如果您需要从您的应用程序访问文件,您可以使用此源代码示例:
@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);
}
}