ACTION_SEND used to send sms

后端 未结 5 1121
故里飘歌
故里飘歌 2021-01-04 19:23

I want to open native application to send sms but there should be already phone number. I found ACTION_SEND but when I\'m calling my function it\'s return error that:

<
5条回答
  •  鱼传尺愫
    2021-01-04 19:44

    In kotlin following code works with number and custom message

    val defaultSmsPackageName = Telephony.Sms.getDefaultSmsPackage(activity)  
                val sendIntent = Intent(Intent.ACTION_SEND)
                sendIntent.type = "text/plain"
                sendIntent.putExtra("address", "sms:"+contactNumber)
                sendIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.share_msg_body))
                Timber.e("defaultSmsPackageName: "+defaultSmsPackageName)
                if (defaultSmsPackageName != null){ //Can be null in case that there is no default, then the user would be able to choose any app that support this intent.
                    sendIntent.setPackage(defaultSmsPackageName)
                    activity!!.startActivity(sendIntent)
                }
    

提交回复
热议问题