gpt4 book ai didi

android - 使用存储访问框架创建文件

转载 作者:行者123 更新时间:2023-11-29 00:08:13 26 4
gpt4 key购买 nike

最近我收到了一位用户的崩溃报告,他试图使用 Storage Access Framework 创建数据库备份。在 Lollipop 设备上。

异常(exception):

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.CREATE_DOCUMENT cat=[android.intent.category.OPENABLE] typ=*/* (has extras) }

我的代码:

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_TITLE, "Backup.db");
intent.setType("*/*");
startActivityForResult(intent, REQUEST_CODE_BACKUP_SAF);

问题:

是否所有 v19+ 设备都真正支持存储访问框架?我们应该如何处理这种情况?

[更新]

从不同设备收到 4 个额外的崩溃报告。

最佳答案

也许它对遇到同样问题的其他人有用,所以这就是我解决问题的方法

Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.putExtra(Intent.EXTRA_TITLE, "Backup.db");
intent.setType("*/*");
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_CODE_BACKUP_SAF);
} else {
// start my custom file browser...
}

关于android - 使用存储访问框架创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32236705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com