Merge pull request #4745 from johnjohndoe/sharecompat
Use ShareCompat.IntentBuilder for sharing content
This commit is contained in:
commit
9534abef19
|
@ -0,0 +1 @@
|
||||||
|
Open share UI provides by the system when sharing media or text.
|
|
@ -305,26 +305,28 @@ fun shareMedia(context: Context, file: File, mediaMimeType: String?) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val sendIntent = ShareCompat.IntentBuilder(context)
|
val chooserIntent = ShareCompat.IntentBuilder(context)
|
||||||
.setType(mediaMimeType)
|
.setType(mediaMimeType)
|
||||||
.setStream(mediaUri)
|
.setStream(mediaUri)
|
||||||
.getIntent()
|
.setChooserTitle(R.string.share)
|
||||||
|
.createChooserIntent()
|
||||||
|
|
||||||
sendShareIntent(context, sendIntent)
|
createChooser(context, chooserIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun shareText(context: Context, text: String) {
|
fun shareText(context: Context, text: String) {
|
||||||
val sendIntent = Intent()
|
val chooserIntent = ShareCompat.IntentBuilder(context)
|
||||||
sendIntent.action = Intent.ACTION_SEND
|
.setType("text/plain")
|
||||||
sendIntent.type = "text/plain"
|
.setText(text)
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, text)
|
.setChooserTitle(R.string.share)
|
||||||
|
.createChooserIntent()
|
||||||
|
|
||||||
sendShareIntent(context, sendIntent)
|
createChooser(context, chooserIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendShareIntent(context: Context, intent: Intent) {
|
private fun createChooser(context: Context, intent: Intent) {
|
||||||
try {
|
try {
|
||||||
context.startActivity(Intent.createChooser(intent, context.getString(R.string.share)))
|
context.startActivity(intent)
|
||||||
} catch (activityNotFoundException: ActivityNotFoundException) {
|
} catch (activityNotFoundException: ActivityNotFoundException) {
|
||||||
context.toast(R.string.error_no_external_application_found)
|
context.toast(R.string.error_no_external_application_found)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue