Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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 如何知道短信在安卓系统中正确发送?_Android_Kotlin_Broadcastreceiver_Android Pendingintent_Android Sms - Fatal编程技术网

Android 如何知道短信在安卓系统中正确发送?

Android 如何知道短信在安卓系统中正确发送?,android,kotlin,broadcastreceiver,android-pendingintent,android-sms,Android,Kotlin,Broadcastreceiver,Android Pendingintent,Android Sms,我正在做短信管理应用程序。 这是我的密码 接收器代码: private val receiver = object : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent) { val id = intent.getIntExtra("id", 0) if (resultCode == Activity.RESULT_OK) {

我正在做短信管理应用程序。 这是我的密码

接收器代码:

private val receiver = object : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent) {
        val id = intent.getIntExtra("id", 0)
        if (resultCode == Activity.RESULT_OK) {
            Log.d("SMS", "Success to sent SMS")
        } else {
            Log.e("SMS", "Failed to send SMS")
        }
    }
}
private fun sendMessage(phone: String, message: String) {
    try {
        Log.d("SMS", "Send SMS")
        val intent = Intent(SENT)
        val sentIntent = PendingIntent.getBroadcast(activity, 0, intent, PendingIntent.FLAG_ONE_SHOT)
        smsManager.sendTextMessage(phone, null, message, sentIntent, null)
    } catch (ex: Exception) {
        Log.e("Error", "error", ex)
    }
}
发送短信方式:

private val receiver = object : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent) {
        val id = intent.getIntExtra("id", 0)
        if (resultCode == Activity.RESULT_OK) {
            Log.d("SMS", "Success to sent SMS")
        } else {
            Log.e("SMS", "Failed to send SMS")
        }
    }
}
private fun sendMessage(phone: String, message: String) {
    try {
        Log.d("SMS", "Send SMS")
        val intent = Intent(SENT)
        val sentIntent = PendingIntent.getBroadcast(activity, 0, intent, PendingIntent.FLAG_ONE_SHOT)
        smsManager.sendTextMessage(phone, null, message, sentIntent, null)
    } catch (ex: Exception) {
        Log.e("Error", "error", ex)
    }
}
当我将消息发送到正确的号码时,接收者可以接收“成功”事件。很好
但当我向随机数(如“123123”)发送消息时,接收方也会收到“成功”事件。太糟糕了
所以我签入了我的手机,但在默认的消息应用程序中有一条失败的消息

所以我的问题是:
为什么要在我的代码的Sentinent中播放成功事件 我如何解决这个问题

请任何人帮帮我。
谢谢

PS. 我已经查看了以下URL。但仍然没有答案


发送状态仅反映手机向陆侧SMSC(服务器)发送短信的情况。当您获得成功时,这意味着信息已成功地从手机传输到服务器。这与邮件实际传递给收件人没有任何关系

如果您希望获得有关交付状态的通知,您需要创建一个附加的
pendingent
,并将其传递给
smsmsmanager

    val intent = Intent(SENT)
    val sentIntent = PendingIntent.getBroadcast(activity, 0, intent,
                            PendingIntent.FLAG_ONE_SHOT)
    val intent2 = Intent(DELIVERY)
    PendingIntent.getBroadcast(activity, 0, intent2,
                            PendingIntent.FLAG_ONE_SHOT)
    smsManager.sendTextMessage(phone, null, message, sentIntent, deliveryIntent)

然后,您的
BroadcastReceiver
可以捕获传递的
Intent
,并确定消息是否成功传递。

我尝试了您的方法。但任何事件都没有传递到deliveryIntent。请编辑您的问题并显示您的代码。请出示您的舱单。