What is Android 11's equivalent of '/dev/null'
Asked Answered
T

2

10

Android 11 introduced multiple changes to file storage and access. Apparently one of them is that one can no longer target output to '/dev/null' (my scenario is actually exactly explained in this old question).

Although the cited question solved the particular issue, one thing remains unanswered: what is Android 11's equivalent to '/dev/null'. That is, if one does not need the output of a particular operation (and in our case it is an operation that creates a biggish file).

Tolson answered 20/1, 2021 at 13:4 Comment(0)
T
2

Eventually I ended up solving my problem the following way (answer tailored to MediaRecorder problem but can be generalized to other situations too):

fun MediaRecorder.setOutputFile(context: Context) {
    val tmpRecordingFolder = File(context.filesDir, "tmp_media")
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        setOutputFile(File(tmpRecordingFolder, "recording.mp3"))
    } else {
        setOutputFile("/dev/null")
    }
}

Basically I am setting the output to be in the internal storage. I hope the file will not get huge and I am deleting the file in as many places in the code as possible. This seems to work on newer devices, currently have not yet ran into storage problems either, but the solution is not rolled out to production yet. Will update my answer if problems are identified.

Tolson answered 5/3, 2021 at 11:18 Comment(0)
A
1

I had the same issue, you'll have to specify a path since MediaRecorder crashes in Android 11 if you don't provide it, in order to avoid writing a massive file you could try to flush the file by stopping / restarting MediaRecorder, I been dealing with this issue for a few days too.

I replied a more detailed answer here: MediaRecorder Android 11 start failed -1004

Arris answered 16/11, 2021 at 16:46 Comment(2)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewFeeler
I edited my answer to make it more understandable.Arris

© 2022 - 2024 — McMap. All rights reserved.