added openBrowser and callToPhoneNumber methods (#18)

This commit is contained in:
Oleg 2019-05-14 14:27:10 +03:00 committed by GitHub
parent 5ecaddcb9c
commit 8a8417b587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -2,7 +2,16 @@ package ru.touchin.extensions
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
fun Context.safeStartActivity(intent: Intent, options: Bundle? = null, resolveFlags: Int = 0): Boolean =
packageManager.resolveActivity(intent, resolveFlags)?.let { startActivity(intent, options) } != null
fun Context.openBrowser(url: String) = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(url))
.let { intent -> safeStartActivity(intent) }
fun Context.callToPhoneNumber(phoneNumber: String) = Intent(Intent.ACTION_VIEW)
.setData(Uri.parse("tel:$phoneNumber"))
.let { intent -> safeStartActivity(intent) }