adding a helper for sharing text intent

This commit is contained in:
tibbi 2020-04-05 19:58:00 +02:00
parent 001319fc84
commit 0b317a1e27
2 changed files with 25 additions and 1 deletions

View file

@ -7,7 +7,7 @@ buildscript {
propMinSdkVersion = 21
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '5.24.16'
propVersionName = '5.24.17'
kotlin_version = '1.3.71'
}

View file

@ -248,6 +248,30 @@ fun Activity.sharePathsIntent(paths: ArrayList<String>, applicationId: String) {
}
}
fun Activity.shareTextIntent(text: String) {
ensureBackgroundThread {
Intent().apply {
action = Intent.ACTION_SEND
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, text)
try {
if (resolveActivity(packageManager) != null) {
startActivity(Intent.createChooser(this, getString(R.string.share_via)))
} else {
toast(R.string.no_app_found)
}
} catch (e: RuntimeException) {
if (e.cause is TransactionTooLargeException) {
toast(R.string.maximum_share_reached)
} else {
showErrorToast(e)
}
}
}
}
}
fun Activity.setAsIntent(path: String, applicationId: String) {
ensureBackgroundThread {
val newUri = getFinalUriFromPath(path, applicationId) ?: return@ensureBackgroundThread