adding an activity extension
This commit is contained in:
parent
8336ec0052
commit
7e9586af09
|
@ -0,0 +1,26 @@
|
|||
package com.simplemobiletools.smsmessenger.extensions
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import com.simplemobiletools.commons.extensions.hideKeyboard
|
||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
|
||||
fun Activity.dialNumber(phoneNumber: String, callback: (() -> Unit)? = null) {
|
||||
hideKeyboard()
|
||||
Intent(Intent.ACTION_DIAL).apply {
|
||||
data = Uri.fromParts("tel", phoneNumber, null)
|
||||
|
||||
try {
|
||||
startActivity(this)
|
||||
callback?.invoke()
|
||||
} catch (e: ActivityNotFoundException) {
|
||||
toast(R.string.no_app_found)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue