diff --git a/stream-log-android-file/src/main/AndroidManifest.xml b/stream-log-android-file/src/main/AndroidManifest.xml index 161fba3..31630d7 100644 --- a/stream-log-android-file/src/main/AndroidManifest.xml +++ b/stream-log-android-file/src/main/AndroidManifest.xml @@ -19,6 +19,7 @@ > + @@ -26,6 +27,7 @@ android:name=".StreamLogFileService" android:enabled="true" android:exported="true" + android:foregroundServiceType="dataSync" > diff --git a/stream-log-android-file/src/main/kotlin/io/getstream/log/file/FileStreamLogger.kt b/stream-log-android-file/src/main/kotlin/io/getstream/log/file/FileStreamLogger.kt index e430a3b..939402c 100644 --- a/stream-log-android-file/src/main/kotlin/io/getstream/log/file/FileStreamLogger.kt +++ b/stream-log-android-file/src/main/kotlin/io/getstream/log/file/FileStreamLogger.kt @@ -115,18 +115,18 @@ public class FileStreamLogger( * This helper ensures safe creation of files by handling edge cases and logging issues to improve * stability across all devices. */ - if (!internalFile.exists()) { - try { + try { + if (!internalFile.exists()) { internalFile.createNewFile() + } - if (internalFile.canWrite()) { - currentFile = internalFile - currentWriter = internalFile.fileWriter() - } - } catch (e: Exception) { - Log.e("FileInit", "Failed to create or write to file: ${internalFile.absolutePath}", e) - return + if (internalFile.canWrite()) { + currentFile = internalFile + currentWriter = internalFile.fileWriter() } + } catch (e: Exception) { + Log.e("FileInit", "Failed to create or write to file: ${internalFile.absolutePath}", e) + return } } }