Catch IOExceptions when doing SU

This commit is contained in:
Mygod
2018-01-13 19:05:59 +08:00
parent f6a5ed9d64
commit d278c5daab
3 changed files with 29 additions and 11 deletions

View File

@@ -5,7 +5,9 @@ import android.net.Uri
import android.os.Bundle
import android.support.customtabs.CustomTabsIntent
import android.support.v4.content.ContextCompat
import android.widget.Toast
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers
import java.io.IOException
class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
private val customTabsIntent by lazy {
@@ -19,11 +21,16 @@ class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
true
}
findPreference("misc.logcat").setOnPreferenceClickListener {
val intent = Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_TEXT, Runtime.getRuntime().exec(arrayOf("logcat", "-d"))
.inputStream.bufferedReader().use { it.readText() })
startActivity(Intent.createChooser(intent, getString(R.string.abc_shareactionprovider_share_with)))
try {
val intent = Intent(Intent.ACTION_SEND)
.setType("text/plain")
.putExtra(Intent.EXTRA_TEXT, Runtime.getRuntime().exec(arrayOf("logcat", "-d"))
.inputStream.bufferedReader().use { it.readText() })
startActivity(Intent.createChooser(intent, getString(R.string.abc_shareactionprovider_share_with)))
} catch (e: IOException) {
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show()
e.printStackTrace()
}
true
}
findPreference("misc.source").setOnPreferenceClickListener {