Error in SMS app running with api levels 25 to 30

I was developing an app which send some receipt to a mobile phone, and I try to use using two Broadcast Receivers, like this:

enter persistSentMessageIfRequired(), mAppInfo.packageName = [******], mPersistMessage = [true] (Ask Gemini)
java.lang.Throwable at com.android.internal.telephony.SMSDispatcher$SmsTracker.persistSentMessageIfRequired(SMSDispatcher.java:1565) at com.android.internal.telephony.SMSDispatcher$SmsTracker.persistOrUpdateMessage(SMSDispatcher.java:1634) 
at com.android.internal.telephony.SMSDispatcher$SmsTracker.onFailed(SMSDispatcher.java:1655) 
at com.android.internal.telephony.SMSDispatcher.sendRawPdu(SMSDispatcher.java:1055) 
at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendText(GsmSMSDispatcher.java:424) 
at com.android.internal.telephony.ImsSMSDispatcher.sendText(ImsSMSDispatcher.java:208) 
at com.android.internal.telephony.IccSmsInterfaceManager.sendTextInternal(IccSmsInterfaceManager.java:466)
at com.android.internal.telephony.IccSmsInterfaceManager.sendText(IccSmsInterfaceManager.java:407)
at com.android.internal.telephony.UiccSmsController.sendTextForSubscriber(UiccSmsController.java:140)
at com.android.internal.telephony.ISms$Stub.onTransact(ISms.java:201)
at android.os.Binder.execTransact(Binder.java:723)

Here is my method sendSMS():

val TAG = "TRACK_SMS_STATUS"

fun sendSMS(activity: Activity, phoneNumber: String, message: String) {
    val send = "SMS_SENT"
    val delivered = "SMS_DELIVERED"

    // Create intents
    val sentIntent = Intent(send)
    val deliveredIntent = Intent(delivered)

    // PendingIntents for sent and delivered
    val sentPI = PendingIntent.getBroadcast(activity, 0, sentIntent, 0)
    val deliveredPI = PendingIntent.getBroadcast(activity, 0, deliveredIntent, 0)

    // Create BroadcastReceiver for sent messages
    val sentReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent?) {
            when (resultCode) {
                AppCompatActivity.RESULT_OK -> {
                    Log.d(TAG, "SMS sent")
                    toast("SMS sent")
                }

                SmsManager.RESULT_ERROR_GENERIC_FAILURE -> {
                    Log.d(TAG, "Generic failure")
                    toast("Generic failure")
                }

                SmsManager.RESULT_ERROR_NO_SERVICE -> {
                    Log.d(TAG, "No service")
                    toast("No service")
                }

                SmsManager.RESULT_ERROR_NULL_PDU -> {
                    Log.d(TAG, "Null PDU")
                    toast("Null PDU")
                }

                SmsManager.RESULT_ERROR_RADIO_OFF -> {
                    Log.d(TAG, "Radio off")
                    toast("Radio off")
                }
            }
        }
    }

    // Create BroadcastReceiver for delivered messages
    val deliveredReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context?, intent: Intent?) {
            when (resultCode) {
                AppCompatActivity.RESULT_OK -> {
                    Log.d(TAG, "SMS delivered")
                    toast("SMS delivered")
                }

                AppCompatActivity.RESULT_CANCELED -> {
                    Log.d(TAG, "SMS not delivered")
                    toast("SMS not delivered")
                }
            }
        }
    }

    // Register the broadcast receivers
    // The constant asked to be added doesn't exist under api levels below 33
    activity.registerReceiver(sentReceiver, IntentFilter(send))
    activity.registerReceiver(deliveredReceiver, IntentFilter(delivered))

    // Send the SMS
    val smsManager = SmsManager.getDefault()
    smsManager.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI)

    // Unregister the receivers after a delay to ensure they catch the broadcasts
    activity.window.decorView.postDelayed({
        activity.unregisterReceiver(sentReceiver)
        activity.unregisterReceiver(deliveredReceiver)
    }, 5000) // Adjust delay as necessary for your context
}

In the lines where I register the receivers I’m getting this warning:

sentReceiver is missing RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED flag for unprotected broadcasts registered for SMS_SENT

So to protect the broadcast receivers I create a custom permission in my manifest:

<permission
    android:name="******.SEND_SMS"
    android:protectionLevel="signature" />

It’s weird due to when I using a custom server the sms is sent without issue, but using the receivers rise this error.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật