I am making SMS Manager application. Here is my code.
Receiver Code:
private val receiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent) {
val id = intent.getIntExtra("id", 0)
if (resultCode == Activity.RESULT_OK) {
Log.d("SMS", "Success to sent SMS")
} else {
Log.e("SMS", "Failed to send SMS")
}
}
}
Send SMS method:
private fun sendMessage(phone: String, message: String) {
try {
Log.d("SMS", "Send SMS")
val intent = Intent(SENT)
val sentIntent = PendingIntent.getBroadcast(activity, 0, intent, PendingIntent.FLAG_ONE_SHOT)
smsManager.sendTextMessage(phone, null, message, sentIntent, null)
} catch (ex: Exception) {
Log.e("Error", "error", ex)
}
}
When I send message to correct number, the receiver can receive "Success" event. It's good!
But when I send message to random number such as "123123123", the receiver also receive "Success" event. It's bad!
So I checked in my phone, but there is failed message in default messaging app.
So my question is:
Why broadcast success event in sentIntent of my code?
How can I fix this problem?
Please anyone help me.
Thanks.
PS. I already looked following URLs. But there is still no answer.