Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

Unable to Send SMS programmatically in Android for some devices

In our app, we are trying to send SMS progrmmatically. For 20% devices app is not able to send SMS. We are getting "RESULT_ERROR_GENERIC_FAILURE" error from sms receiver in most cases and in most cases sms is not being sent from device itself.

Below is the code snippet we are using for sending sms.

private fun sendSms(subscriptionId: Int, number: String, smsText: String, sentPI: PendingIntent?, listener: ISmsSendListener) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            SmsManager.getSmsManagerForSubscriptionId(subscriptionId).sendTextMessage(number, null, smsText, sentPI, null)
           
        } else {
            SmsManager.getDefault().sendTextMessage(number, null, smsText, sentPI, null)
          
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...