fix: BLE 로그 Downloads 폴더에 저장 (파일 탐색기 접근 가능)
- exportToDownloads(): Downloads/VesiScan_BLE_날짜.log 로 저장 - 실패 시 fallback으로 내부 저장소에 저장 - Toast로 저장 경로 안내 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -207,11 +207,7 @@ class BleDebugLogger private constructor(private val context: Context) {
|
||||
|
||||
// ── File Export ──
|
||||
|
||||
fun exportToFile(): File {
|
||||
val fileName = "ble_debug_${dateFmt.format(Date())}.log"
|
||||
val file = File(logDir, fileName)
|
||||
|
||||
file.bufferedWriter().use { writer ->
|
||||
private fun writeLogContent(writer: java.io.BufferedWriter) {
|
||||
writer.write("=== VesiScan BLE Debug Log ===\n")
|
||||
writer.write("Device: $deviceName\n")
|
||||
writer.write("Session: ${dateFmt.format(Date(sessionStart))}\n")
|
||||
@@ -230,9 +226,28 @@ class BleDebugLogger private constructor(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fun exportToFile(): File {
|
||||
val fileName = "ble_debug_${dateFmt.format(Date())}.log"
|
||||
val file = File(logDir, fileName)
|
||||
file.bufferedWriter().use { writeLogContent(it) }
|
||||
return file
|
||||
}
|
||||
|
||||
/** Downloads 폴더에 저장 (파일 탐색기에서 바로 접근 가능) */
|
||||
fun exportToDownloads(): File? {
|
||||
return try {
|
||||
val downloadsDir = android.os.Environment.getExternalStoragePublicDirectory(
|
||||
android.os.Environment.DIRECTORY_DOWNLOADS
|
||||
)
|
||||
val fileName = "VesiScan_BLE_${dateFmt.format(Date())}.log"
|
||||
val file = File(downloadsDir, fileName)
|
||||
file.bufferedWriter().use { writeLogContent(it) }
|
||||
file
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun exportToJsonFile(): File {
|
||||
val fileName = "ble_debug_${dateFmt.format(Date())}.jsonl"
|
||||
val file = File(logDir, fileName)
|
||||
|
||||
+8
-3
@@ -1115,11 +1115,16 @@ private fun BleDebugPanel(bleManager: BleManager) {
|
||||
Icon(Icons.Default.ContentCopy, "Copy", tint = Color.Gray, modifier = Modifier.size(16.dp))
|
||||
}
|
||||
|
||||
// Export file button
|
||||
// Export to Downloads
|
||||
IconButton(
|
||||
onClick = {
|
||||
val file = logger.exportToFile()
|
||||
android.widget.Toast.makeText(context, "Saved: ${file.name}", android.widget.Toast.LENGTH_SHORT).show()
|
||||
val file = logger.exportToDownloads()
|
||||
if (file != null) {
|
||||
android.widget.Toast.makeText(context, "Downloads/${file.name} 저장 완료", android.widget.Toast.LENGTH_LONG).show()
|
||||
} else {
|
||||
logger.exportToFile()
|
||||
android.widget.Toast.makeText(context, "내부 저장소에 저장됨", android.widget.Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
},
|
||||
modifier = Modifier.size(32.dp)
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user