Added capability to send SMS messages
This commit is contained in:
@ -34,6 +34,8 @@
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
<uses-permission android:name="android.permission.SEND_SMS"
|
||||
tools:ignore="SmsAndCallLogPolicy" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.telephony"
|
||||
|
||||
@ -552,25 +552,14 @@ private fun NewMessage(
|
||||
msg.add()
|
||||
var msgUri = ""
|
||||
addMessage(msg)
|
||||
if (Utils.isTelUri(peerUri))
|
||||
if (ua.account.telProvider == "") {
|
||||
dialogMessage.value = String.format(
|
||||
ctx.getString(R.string.no_telephony_provider),
|
||||
Utils.plainAor(aor)
|
||||
)
|
||||
showDialog.value = true
|
||||
}
|
||||
else {
|
||||
msgUri = Utils.telToSip(peerUri, ua.account)
|
||||
}
|
||||
else
|
||||
msgUri = peerUri
|
||||
if (msgUri != "")
|
||||
if (Api.message_send(ua.uap,
|
||||
msgUri,
|
||||
msgText,
|
||||
time.toString()
|
||||
) != 0) {
|
||||
if (ua.account.isMobile) {
|
||||
val destination = Utils.uriUserPart(peerUri)
|
||||
if (Utils.sendSms(ctx, destination, msgText)) {
|
||||
msg.direction = MESSAGE_UP
|
||||
newMessage.value = TextFieldValue("")
|
||||
viewModel.updateAorPeerMessage(aor, peerUri, "")
|
||||
keyboardController?.hide()
|
||||
} else {
|
||||
Toast.makeText(
|
||||
ctx, "${ctx.getString(R.string.message_failed)}!",
|
||||
Toast.LENGTH_SHORT
|
||||
@ -578,11 +567,39 @@ private fun NewMessage(
|
||||
msg.direction = MESSAGE_UP_FAIL
|
||||
msg.responseReason = ctx.getString(R.string.message_failed)
|
||||
}
|
||||
else {
|
||||
newMessage.value = TextFieldValue("")
|
||||
viewModel.updateAorPeerMessage(aor, peerUri, "")
|
||||
keyboardController?.hide()
|
||||
}
|
||||
} else {
|
||||
if (Utils.isTelUri(peerUri))
|
||||
if (ua.account.telProvider == "") {
|
||||
dialogMessage.value = String.format(
|
||||
ctx.getString(R.string.no_telephony_provider),
|
||||
Utils.plainAor(aor)
|
||||
)
|
||||
showDialog.value = true
|
||||
} else {
|
||||
msgUri = Utils.telToSip(peerUri, ua.account)
|
||||
}
|
||||
else
|
||||
msgUri = peerUri
|
||||
if (msgUri != "")
|
||||
if (Api.message_send(
|
||||
ua.uap,
|
||||
msgUri,
|
||||
msgText,
|
||||
time.toString()
|
||||
) != 0
|
||||
) {
|
||||
Toast.makeText(
|
||||
ctx, "${ctx.getString(R.string.message_failed)}!",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
msg.direction = MESSAGE_UP_FAIL
|
||||
msg.responseReason = ctx.getString(R.string.message_failed)
|
||||
} else {
|
||||
newMessage.value = TextFieldValue("")
|
||||
viewModel.updateAorPeerMessage(aor, peerUri, "")
|
||||
keyboardController?.hide()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
containerColor = MaterialTheme.colorScheme.secondary,
|
||||
|
||||
@ -805,23 +805,22 @@ private fun BottomBar(ctx: Context, viewModel: ViewModel, navController: NavCont
|
||||
)
|
||||
}
|
||||
|
||||
if (!isMobile)
|
||||
IconButton(
|
||||
enabled = aor.isNotEmpty(),
|
||||
onClick = {
|
||||
navController.navigate("chats/$aor")
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.size(buttonSize)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.Chat,
|
||||
contentDescription = null,
|
||||
Modifier.size(buttonSize),
|
||||
tint = if (hasUnreadMessages) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.secondary
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
enabled = aor.isNotEmpty(),
|
||||
onClick = {
|
||||
navController.navigate("chats/$aor")
|
||||
},
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.size(buttonSize)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.AutoMirrored.Filled.Chat,
|
||||
contentDescription = null,
|
||||
Modifier.size(buttonSize),
|
||||
tint = if (hasUnreadMessages) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.secondary
|
||||
)
|
||||
}
|
||||
|
||||
IconButton(
|
||||
enabled = aor.isNotEmpty(),
|
||||
|
||||
@ -1440,4 +1440,20 @@ object Utils {
|
||||
Log.e(TAG, "--------------------------------------")
|
||||
}
|
||||
|
||||
fun sendSms(ctx: Context, destination: String, message: String): Boolean {
|
||||
return try {
|
||||
val smsManager = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||
ctx.getSystemService(android.telephony.SmsManager::class.java)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
android.telephony.SmsManager.getDefault()
|
||||
}
|
||||
smsManager.sendTextMessage(destination, null, message, null, null)
|
||||
true
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to send SMS: ${e.message}")
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user