MOBILE-1144

This commit is contained in:
Vladimir Golyshev 2021-09-13 02:31:27 +03:00
parent e8a94c7f87
commit d718d82e59
1 changed files with 13 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.Browser
fun Context.safeStartActivity(intent: Intent, options: Bundle? = null, resolveFlags: Int = 0) =
try {
@ -15,6 +16,18 @@ fun Context.openBrowser(url: String) = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(url))
.let { intent -> safeStartActivity(intent) }
fun Context.openBrowserWithHeaders(url: String, headersMap: Map<String, String>) = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(url))
.let { intent ->
val bundle = Bundle().apply {
headersMap.forEach { (key, value) ->
putString(key, value)
}
}
intent.putExtra(Browser.EXTRA_HEADERS, bundle)
safeStartActivity(intent)
}
fun Context.callToPhoneNumber(phoneNumber: String) = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("tel:$phoneNumber"))
.let { intent -> safeStartActivity(intent) }