我发了一个发送申请。如何在没有实际设备的情况下检查邮件发送?
sendSms.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
//Toast.makeText(getApplicationContext(),template+"and"+phoneNumber,Toast.LENGTH_LONG).show();
if (phoneNumber.length()>0 && template.length()>0)
{
sendSMS(phoneNumber, template);
}
else
Toast.makeText(getApplicationContext(), "please select name & template",Toast.LENGTH_SHORT).show();
}
private void sendSMS(String phoneNumber, String template)
{
PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0,new Intent(getApplicationContext(),Test2Activity.class), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, template, pi, null);
}
});
答案 0 :(得分:3)
答案 1 :(得分:0)
您可以这样检查: -
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent) {
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));
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
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));
Umesh的回答是绝对正确的,但如果你想以实用的方式检查它,那么你必须在你的Activity中添加这个代码。