我正在尝试在我的
android模拟器上创建一个目录,但是我不能这样做,我已经拥有了manifest write_storage的权限,并且我没有得到任何错误,但mkdir()返回false,我验证外部存储是否也可写它是,它在物理设备上工作我的代码:
/// Cria uma nova pasta para colocar o backup File direct = new File(Environment.getExternalStorageDirectory(),"/Financas RW Backup"); try { if (!direct.exists()) { if(isExternalStorageWritable()&&isExternalStorageReadable()) { if( direct.mkdir()) { fachada.showMessage(ExportImportDB.this," Criado"); }else{ fachada.showMessage(ExportImportDB.this," Não Criado"); } } } } catch (Exception e) { fachada.showMessage(this,e.toString()); }
解决方法
你必须选择:
>将compileSdkVersion和targetSdkVersion降级为build.gradle中的较低版本
> Android 6上需要运行时请求写入权限
.
我个人不建议第一个.欲了解更多信息:
> Android 6.0 Marshmallow. Cannot write to SD Card
> Google Play services 8.1 and Android 6.0 Permissions
希望这可以帮助!!