add helper extensions for sharing uris
This commit is contained in:
parent
873db92aec
commit
5c251a1183
2 changed files with 29 additions and 1 deletions
|
@ -31,7 +31,7 @@ ext {
|
|||
propMinSdkVersion = 16
|
||||
propTargetSdkVersion = propCompileSdkVersion
|
||||
propVersionCode = 1
|
||||
propVersionName = '2.33.3'
|
||||
propVersionName = '2.33.4'
|
||||
kotlin_version = '1.1.51'
|
||||
support_libs = '26.0.2'
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.Intent
|
|||
import android.media.MediaScannerConnection
|
||||
import android.net.Uri
|
||||
import android.os.Looper
|
||||
import android.os.TransactionTooLargeException
|
||||
import android.provider.DocumentsContract
|
||||
import android.support.v4.provider.DocumentFile
|
||||
import android.view.View
|
||||
|
@ -100,6 +101,33 @@ fun Activity.launchViewIntent(url: String) {
|
|||
startActivity(browserIntent)
|
||||
}
|
||||
|
||||
fun Activity.shareUri(uri: Uri, applicationId: String) {
|
||||
val shareTitle = resources.getString(R.string.share_via)
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_SEND
|
||||
putExtra(Intent.EXTRA_STREAM, ensurePublicUri(uri, applicationId))
|
||||
type = getMimeTypeFromUri(uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
startActivity(Intent.createChooser(this, shareTitle))
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.shareUris(uris: ArrayList<Uri>, applicationId: String) {
|
||||
val newUris = uris.map { ensurePublicUri(it, applicationId) } as ArrayList<Uri>
|
||||
val shareTitle = resources.getString(R.string.share_via)
|
||||
Intent().apply {
|
||||
action = Intent.ACTION_SEND_MULTIPLE
|
||||
type = newUris.getMimeType()
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
putParcelableArrayListExtra(Intent.EXTRA_STREAM, newUris)
|
||||
try {
|
||||
startActivity(Intent.createChooser(this, shareTitle))
|
||||
} catch (e: TransactionTooLargeException) {
|
||||
toast(R.string.maximum_share_reached)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Activity.openFile(uri: Uri, forceChooser: Boolean, applicationId: String) {
|
||||
val newUri = ensurePublicUri(uri, applicationId)
|
||||
val mimeType = getMimeTypeFromUri(newUri)
|
||||
|
|
Loading…
Reference in a new issue