Android 12:可以将应用程序上传到Google Play时,可以在下载中创建新文件夹
当Code Bellow作为应用程序的一部分是在本地执行(直接从Android Studio启动)时,它的工作正常。
String folderName = Environment.DIRECTORY_DOWNLOADS;
File folder = new File(Environment.getExternalStoragePublicDirectory(folderName) + "/SampleApp/");
if (!folder.mkdirs()) {
FirebaseCrashlytics.getInstance().recordException(new Exception("Storage access class: can't create folder");
Log.d("Debug", "Can't create new folder on path: " + folder.getPath());
return false;
}
return folder.exists();
创建新文件夹的完整路径是:
/storage/emulated/0/Download/SampleApp
但是,当与应用程序的一部分相同的代码上传到Google Play,然后安装到同一手机时,文件夹无法创建,并且触发了异常。记录的调试路径是相同的:
/storage/emulated/0/Download/SampleApp
我仅在Android 12设备上遇到问题。特定的东西从Android 11变为12吗?我还尝试使用mkdir()
,但最终结果是相同的。 Inbetweeen这两种测试都显然删除了SampleApp文件夹,因此当我尝试从Google Play尝试应用程序版本时,它不存在。
When code bellow as a part of application is executed locally (directly started from Android Studio) it works correct.
String folderName = Environment.DIRECTORY_DOWNLOADS;
File folder = new File(Environment.getExternalStoragePublicDirectory(folderName) + "/SampleApp/");
if (!folder.mkdirs()) {
FirebaseCrashlytics.getInstance().recordException(new Exception("Storage access class: can't create folder");
Log.d("Debug", "Can't create new folder on path: " + folder.getPath());
return false;
}
return folder.exists();
The full path where new folder gets created is:
/storage/emulated/0/Download/SampleApp
But when the same code as a part of application gets uploaded to Google Play and then installed to the same phone, folder can't create and an exception gets triggered. Logged debug path is the same:
/storage/emulated/0/Download/SampleApp
I get the problem only on Android 12 devices. Has something specific changed from Android 11 to 12? I also tried using mkdir()
but end result is the same. Inbetweeen both tests I obviously removed the SampleApp folder, so it doesn't exist when I try app version from Google Play.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过大量尝试,我发现了:
java.nio.file
做到了这些技巧;而不是使用mkdir()
。After much trying I found out that:
From:
java.nio.file
did the trick; instead of usingmkdir()
.