mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
adding an activity extension
This commit is contained in:
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user