gpt4 book ai didi

Java android 10 创建文件的问题

转载 作者:行者123 更新时间:2023-12-01 18:52:22 25 4
gpt4 key购买 nike

私有(private) boolean 值 checkPermissions() { listPermissionsNeeded = new ArrayList<>();

int permissionRead = ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
int permissionWrite = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);

if (permissionRead != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.READ_EXTERNAL_STORAGE);
}
if (permissionWrite != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
}

if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this, listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), REQUEST_ID_MULTIPLE_PERMISSIONS);
return false;
}
return true;

}

public static void parseBase64ToPDFAndNoOpen(String base64, String cardId) throws IOException {

FileOutputStream os;
File dwldsPath = new File(Environment.getExternalStorageDirectory() + "/" + File.separator + cardId + ".pdf");
if (!dwldsPath.exists()) {
dwldsPath.createNewFile();
byte[] pdfAsBytes = Base64.decode(base64, 0);
os = new FileOutputStream(dwldsPath, false);
os.write(pdfAsBytes);
os.flush();
os.close();
}
}

在 android 9 上一切正常,但在 andorid 10 上我有这个:java.io.IOException:权限被拒绝所有权限都已授予

最佳答案

Android 10 prohibits使用外部存储。使用 scoped storage 代替.

范围存储是应用程序目录内的文件夹

关于Java android 10 创建文件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59712483/

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