短信有两种方式:一种是获得授权然后直接发送,pendingIntent监控结果,二是交给系统调用默认软件预填。
一. 短信-获得授权,直接发送
1. AndroidManifest.xml 注册授权
<uses-permission android:name="android.permission.SEND_SMS"/>
2。注册监听
var sentPI: PendingIntent? = null
sentPI = PendingIntent.getBroadcast(this, 0, Intent(SENT_SMS), 0)
registerReceiver(object : BroadcastReceiver() {
override fun onReceive(arg0: Context?, arg1: Intent?) {
when (getResultCode()) {
Activity.RESULT_OK -> Toast.makeText(baseContext, "SMS sent", Toast.LENGTH_SHORT).show()
SmsManager.RESULT_ERROR_GENERIC_FAILURE -> Toast.makeText(baseContext, "Generic failure", Toast.LENGTH_SHORT).show()
SmsManager.RESULT_ERROR_NO_SERVICE -> Toast.makeText(baseCont