X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FLogcatActivity.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FLogcatActivity.kt;h=25c2bfc6e3d3a1af9b47b0ba8bd5f482b6660be3;hp=75efc825baf53913e7fa70d833df37ebea2f46a2;hb=83fa40449d1160836c4066c99fe3c141d982917a;hpb=2bd8b7edef80b4b10cb809a198b4624c6c740c86 diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/LogcatActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/LogcatActivity.kt index 75efc825..25c2bfc6 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/LogcatActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/LogcatActivity.kt @@ -43,6 +43,11 @@ import com.stoutner.privacybrowser.BuildConfig import com.stoutner.privacybrowser.R +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + import java.io.BufferedReader import java.io.IOException import java.io.InputStreamReader @@ -72,11 +77,16 @@ class LogcatActivity : AppCompatActivity() { // Open an output stream. val outputStream = contentResolver.openOutputStream(fileUri)!! - // Write the logcat string to the output stream. - outputStream.write(logcatString.toByteArray(StandardCharsets.UTF_8)) + // Save the logcat using a coroutine with Dispatchers.IO. + CoroutineScope(Dispatchers.Main).launch { + withContext(Dispatchers.IO) { + // Write the logcat string to the output stream. + outputStream.write(logcatString.toByteArray(StandardCharsets.UTF_8)) - // Close the output stream. - outputStream.close() + // Close the output stream. + outputStream.close() + } + } // Initialize the file name string from the file URI last path segment. var fileNameString = fileUri.lastPathSegment