我正在编写一个发送短信(使用SmsManager)的应用程序,我想知道消息是否发送成功。我将在content://sms/sent上使用ContentObserver,但可能不是一个好主意,因为我只想处理我的应用发送的消息。

有什么建议吗?

最佳答案

使用此代码将为您提供帮助。

public void onReceive(Context arg0, Intent arg1) {
    switch (getResultCode()) {
        case Activity.RESULT_OK:
            //message sent
            break;

        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
            Toast.makeText(getBaseContext(), "Generic failure",
            Toast.LENGTH_SHORT).show();
            break;

        case SmsManager.RESULT_ERROR_NO_SERVICE:
            Toast.makeText(getBaseContext(), "No service",
            Toast.LENGTH_SHORT).show();
            break;

        case SmsManager.RESULT_ERROR_NULL_PDU:
            Toast.makeText(getBaseContext(), "Null PDU",
            Toast.LENGTH_SHORT).show();
            break;

        case SmsManager.RESULT_ERROR_RADIO_OFF:
            Toast.makeText(getBaseContext(), "Radio off",
            Toast.LENGTH_SHORT).show();
            break;

    }
}

10-07 19:28
查看更多