我正在逐字使用http://mobiforge.com/developing/story/sms-messaging-android代码示例,除了我更改了:
import android.telephony.gsm.SmsManager;
至:
import android.telephony.SmsManager;
SMS 发送良好,但我没有收到它已发送的 TOAST 消息(发送到网络)。我正在尝试将 SMS 集成到我的应用程序中,这很重要。我相信这是可以做到的,因为股票短信应用程序如何知道何时停止显示“发送圈”。相关代码部分如下:
//---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 是否已更改或示例是否存在问题?如果有帮助,我正在测试三星 GSIII。我的旧测试是在 Epic 上进行的。