feat: call directly instead of launching dialpad (#563)

Refs: https://github.com/FossifyOrg/Messages/issues/562
This commit is contained in:
Naveen Singh 2025-10-23 20:39:09 +05:30 committed by GitHub
parent 9773ccb82b
commit f3408f1f9a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 11 deletions

View file

@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
### Changed
- Calling now works directly without launching dialpad ([#562])
## [1.5.0] - 2025-10-18 ## [1.5.0] - 2025-10-18
### Added ### Added
@ -187,7 +189,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#376]: https://github.com/FossifyOrg/Messages/issues/376 [#376]: https://github.com/FossifyOrg/Messages/issues/376
[#456]: https://github.com/FossifyOrg/Messages/issues/456 [#456]: https://github.com/FossifyOrg/Messages/issues/456
[#461]: https://github.com/FossifyOrg/Messages/issues/461 [#461]: https://github.com/FossifyOrg/Messages/issues/461
[#561]: https://github.com/FossifyOrg/Messages/issues/561 [#561]: https://github.com/FossifyOrg/Messages/pull/561
[#562]: https://github.com/FossifyOrg/Messages/issues/562
[Unreleased]: https://github.com/FossifyOrg/Messages/compare/1.5.0...HEAD [Unreleased]: https://github.com/FossifyOrg/Messages/compare/1.5.0...HEAD
[1.5.0]: https://github.com/FossifyOrg/Messages/compare/1.4.0...1.5.0 [1.5.0]: https://github.com/FossifyOrg/Messages/compare/1.4.0...1.5.0

View file

@ -14,6 +14,7 @@
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" /> <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission <uses-permission

View file

@ -5,6 +5,7 @@ import android.content.ActivityNotFoundException
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.provider.ContactsContract import android.provider.ContactsContract
import org.fossify.commons.activities.BaseSimpleActivity
import org.fossify.commons.extensions.getMimeType import org.fossify.commons.extensions.getMimeType
import org.fossify.commons.extensions.hideKeyboard import org.fossify.commons.extensions.hideKeyboard
import org.fossify.commons.extensions.isPackageInstalled import org.fossify.commons.extensions.isPackageInstalled
@ -14,6 +15,7 @@ import org.fossify.commons.extensions.showErrorToast
import org.fossify.commons.extensions.toast import org.fossify.commons.extensions.toast
import org.fossify.commons.helpers.CONTACT_ID import org.fossify.commons.helpers.CONTACT_ID
import org.fossify.commons.helpers.IS_PRIVATE import org.fossify.commons.helpers.IS_PRIVATE
import org.fossify.commons.helpers.PERMISSION_CALL_PHONE
import org.fossify.commons.helpers.SimpleContactsHelper import org.fossify.commons.helpers.SimpleContactsHelper
import org.fossify.commons.helpers.ensureBackgroundThread import org.fossify.commons.helpers.ensureBackgroundThread
import org.fossify.commons.models.SimpleContact import org.fossify.commons.models.SimpleContact
@ -21,18 +23,21 @@ import org.fossify.messages.activities.ConversationDetailsActivity
import org.fossify.messages.helpers.THREAD_ID import org.fossify.messages.helpers.THREAD_ID
import java.util.Locale import java.util.Locale
fun Activity.dialNumber(phoneNumber: String, callback: (() -> Unit)? = null) { fun BaseSimpleActivity.dialNumber(phoneNumber: String, callback: (() -> Unit)? = null) {
hideKeyboard() hideKeyboard()
Intent(Intent.ACTION_DIAL).apply { handlePermission(PERMISSION_CALL_PHONE) {
data = Uri.fromParts("tel", phoneNumber, null) val action = if (it) Intent.ACTION_CALL else Intent.ACTION_DIAL
Intent(action).apply {
data = Uri.fromParts("tel", phoneNumber, null)
try { try {
startActivity(this) startActivity(this)
callback?.invoke() callback?.invoke()
} catch (_: ActivityNotFoundException) { } catch (_: ActivityNotFoundException) {
toast(org.fossify.commons.R.string.no_app_found) toast(org.fossify.commons.R.string.no_app_found)
} catch (e: Exception) { } catch (e: Exception) {
showErrorToast(e) showErrorToast(e)
}
} }
} }
} }