@@ -19,6 +19,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
1919import androidx.recyclerview.widget.RecyclerView
2020import com.google.android.material.snackbar.Snackbar
2121import info.hannes.logcat.ui.R
22+ import kotlinx.coroutines.CoroutineScope
2223import kotlinx.coroutines.Dispatchers
2324import kotlinx.coroutines.launch
2425import kotlinx.coroutines.withContext
@@ -223,33 +224,37 @@ abstract class LogBaseFragment : Fragment() {
223224 }
224225
225226 private fun sendLogContent (filterLogs : List <String >, filename : String ) {
226- val logToSend = File (requireActivity().externalCacheDir, filename)
227- logToSend.writeText(filterLogs.joinToString(" \n " ))
228-
229- val intent = Intent (Intent .ACTION_SEND )
230-
231- val logsUri = FileProvider .getUriForFile(requireContext(), context?.applicationContext?.packageName + " .provider" , logToSend)
232-
233- intent.putExtra(Intent .EXTRA_EMAIL , emailAddress)
234- val subject = String .format(filename, getString(R .string.app_name))
235- intent.putExtra(Intent .EXTRA_SUBJECT , subject)
236- intent.flags = Intent .FLAG_ACTIVITY_NEW_TASK
237- intent.type = MAIL_ATTACHMENT_TYPE
238- intent.putExtra(Intent .EXTRA_STREAM , logsUri)
239- try {
240- // prevent from a "exposed beyond app through ClipData.Item.getUri()"
241- // https://stackoverflow.com/questions/48117511/exposed-beyond-app-through-clipdata-item-geturi
242- val builder = StrictMode .VmPolicy .Builder ()
243- StrictMode .setVmPolicy(builder.build())
244-
245- startActivity(Intent .createChooser(intent, " $filename ..." ))
246- } catch (e: ActivityNotFoundException ) {
247- val snackBar = Snackbar .make(
227+ CoroutineScope (Dispatchers .IO ).launch {
228+ val logToSend = File (requireActivity().externalCacheDir, filename)
229+ logToSend.writeText(filterLogs.joinToString(" \n " ))
230+
231+ val intent = Intent (Intent .ACTION_SEND )
232+
233+ val logsUri = FileProvider .getUriForFile(requireContext(), context?.applicationContext?.packageName + " .provider" , logToSend)
234+
235+ intent.putExtra(Intent .EXTRA_EMAIL , emailAddress)
236+ val subject = String .format(filename, getString(R .string.app_name))
237+ intent.putExtra(Intent .EXTRA_SUBJECT , subject)
238+ intent.flags = Intent .FLAG_ACTIVITY_NEW_TASK
239+ intent.type = MAIL_ATTACHMENT_TYPE
240+ intent.putExtra(Intent .EXTRA_STREAM , logsUri)
241+ try {
242+ // prevent from a "exposed beyond app through ClipData.Item.getUri()"
243+ // https://stackoverflow.com/questions/48117511/exposed-beyond-app-through-clipdata-item-geturi
244+ val builder = StrictMode .VmPolicy .Builder ()
245+ StrictMode .setVmPolicy(builder.build())
246+
247+ startActivity(Intent .createChooser(intent, " $filename ..." ))
248+ } catch (e: ActivityNotFoundException ) {
249+ val snackBar = Snackbar .make(
248250 requireActivity().findViewById(android.R .id.content),
249251 R .string.log_send_no_app,
250252 Snackbar .LENGTH_LONG
251- )
252- snackBar.show()
253+ )
254+ CoroutineScope (Dispatchers .Main ).launch {
255+ snackBar.show()
256+ }
257+ }
253258 }
254259 }
255260
0 commit comments