Android 12:可以将应用程序上传到Google Play时,可以在下载中创建新文件夹

发布于 2025-02-11 21:02:41 字数 888 浏览 0 评论 0原文

当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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-黛色若梦 2025-02-18 21:02:41

经过大量尝试,我发现了:

Files.createDirectory()

java.nio.file做到了这些技巧;而不是使用mkdir()

After much trying I found out that:

Files.createDirectory()

From: java.nio.file did the trick; instead of using mkdir().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文