Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用意向创建选择器向WhatsApp和SMS发送文本消息不再工作_Android_Sms_Whatsapp - Fatal编程技术网

Android 使用意向创建选择器向WhatsApp和SMS发送文本消息不再工作

Android 使用意向创建选择器向WhatsApp和SMS发送文本消息不再工作,android,sms,whatsapp,Android,Sms,Whatsapp,下面的代码一周前就可以使用了。它的目的是允许用户选择是否要使用WhatsApp或SMS发送文本消息,但现在,当我选择WhatsApp时,它什么都不做,尽管SMS一直在工作 查看正在打印的日志:2018-10-25 18:28:28.915 2147-6714/?I/ActivityManager:START u0{act=android.intent.action.SENDTO dat=smsto:xxxxxxxxxx flg=0x3000000 cmp=com.whatsapp/.Conver

下面的代码一周前就可以使用了。它的目的是允许用户选择是否要使用WhatsApp或SMS发送文本消息,但现在,当我选择WhatsApp时,它什么都不做,尽管SMS一直在工作

查看正在打印的日志:
2018-10-25 18:28:28.915 2147-6714/?I/ActivityManager:START u0{act=android.intent.action.SENDTO dat=smsto:xxxxxxxxxx flg=0x3000000 cmp=com.whatsapp/.Conversation(有附加项)}从uid 10096开始,即使传递带有国家代码的有效数字,它也会打印
smsto:xxxxxxxxxxxxxx

是否有用于此目的的工作代码或了解此问题

fun sendMessageToNumber(number: String, text: String) {
    val cleanNumber = number.cleanText()
    val uri = Uri.parse("smsto:$cleanNumber")
    val sendIntent = Intent(Intent.ACTION_SENDTO, uri)
    sendIntent.putExtra("sms_body", text)
    context?.startActivity(Intent.createChooser(sendIntent, context.getString(R.string.fragment_account_chooser_message_title)))
  }

在我的一个项目中,我使用以下代码发送whatsapp消息:

fun sendWhatsappMsg(){
            var toNumber = "+91 xxxxx xxxxx" // contains spaces.
            toNumber = toNumber.replace("+", "").replace(" ", "")

            val sendIntent = Intent("android.intent.action.MAIN")
            sendIntent.putExtra("jid", "$toNumber@s.whatsapp.net")
            sendIntent.putExtra(Intent.EXTRA_TEXT, "Hello")
            sendIntent.action = Intent.ACTION_SEND
            sendIntent.setPackage("com.whatsapp")
            sendIntent.type = "text/plain"
            startActivity(sendIntent)
}
为了发送短信,我使用了以下代码:

fun sendTextMsg(){
           val phone = "xxxxxxxxxx"
           val msg = "smsto:" + phone
           val smsUri = Uri.parse(msg)
           val smsIntent = Intent(Intent.ACTION_SENDTO, smsUri)
           startActivity(smsIntent)
}
你可以试试这个。两个人都在为我工作