我在用http://mobiforge.com/developing/story/sms-messaging-android http://mobiforge.com/developing/story/sms-messaging-android逐字逐句的代码示例,除了我更改的事实:
import android.telephony.gsm.SmsManager;
to:
import android.telephony.SmsManager;
短信发送正常,但我没有收到已发送的 TOAST 消息(发送到网络)。我正在尝试将短信集成到我的应用程序中,这很重要。我确信这是可以做到的,因为否则股票短信应用程序如何知道何时停止显示“发送圈”。相关代码部分如下:
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
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;
}
}
}, new IntentFilter(SENT));
//---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
我正在使用 Jelly Bean ROM,但我相信不久前我在 Gingerbread 和 ICS 上测试了相同的部分,得到了相同的结果。 API 是否已更改或者示例是否存在问题?我正在 Sasmsung GSIII 上进行测试,如果有帮助的话。我以前的测试是在 Epic 上进行的。