Last active
July 8, 2019 08:39
-
-
Save zmdominguez/be341240af8e9637ac6ffd5605665cc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun saveLogs() { | |
val debugDirectory = getStorageDirectory(this) | |
val logFile = File(debugDirectory, "logcat" + System.currentTimeMillis() + ".txt") | |
try { | |
var process = Runtime.getRuntime().exec("logcat -c") | |
process = Runtime.getRuntime().exec("logcat -f $logFile") | |
} catch (e: IOException) { | |
Timber.d(e) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun sendLogs(context: Context) { | |
val allFiles = getFilesInDebugFolder(context) | |
val emailIntent = Intent(android.content.Intent.ACTION_SEND_MULTIPLE) | |
emailIntent.type = "plain/text" | |
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Shop App Log Dump") | |
val uri = arrayListOf<Uri>() | |
allFiles.forEach { file -> | |
uri.add(FileProvider.getUriForFile(context, "${BuildConfig.APPLICATION_ID}.provider", file)) | |
} | |
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uri) | |
try { | |
startActivity(Intent.createChooser(emailIntent, "Email logs")) | |
} catch (e: ActivityNotFoundException) { | |
Toast.makeText(activity, "No email clients available!", Toast.LENGTH_SHORT).show() | |
} | |
} | |
private fun getFilesInDebugFolder(context: Context): Array<out File> { | |
val storageDirectory = getStorageDirectory(context) | |
return storageDirectory.listFiles().orEmpty() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment