How to Record and Read Files on Android 11(API 30)

Asked

Viewed 20 times

0

When I run the APP and at the time of reading and downloading a PDF file, I get the error of:

corrupted or missing file.

I know that Android 11(API 30) has problems with external files.

This is my code:

[Obsolete]
    public async Task<string> SaveFileToDisk(string fileName, byte[] bytes)
    { 

    if (!Directory.Exists(_rootDir))
        Directory.CreateDirectory(_rootDir);

    var filePath = Path.Combine(_rootDir, fileName);

    File.WriteAllBytes(filePath, bytes);

    return filePath;
}

When I come to this line Directory.CreateDirectory(_rootDir); the application generates the above mentioned error.

The file exists (PDF) and in previous versions runs well. I know that Android 11 has problems with Read/Write in external directories. I cleared the permits: Readexternalstorage, Writeexternalstorage, Manageexternalstorage.

And yet I still keep catching these mistakes.

How do I fix it?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.