在Android应用程序中发送短信
我提出了一个发送申请。在没有实际设备的情况下,如何检查邮件发送在Android应用程序中发送短信,android,Android,我提出了一个发送申请。在没有实际设备的情况下,如何检查邮件发送 sendSms.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //Toast.makeText(getApplicationContext(),template+"and"+phoneNumber,Toast.LENGTH_LONG).show(); if (phoneNumb
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);
}
});
您可以这样检查:-
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的答案绝对正确,但如果您想实际检查,则必须在活动中添加此代码。您可以这样检查:-
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的回答绝对正确,但如果您想实际检查,则必须在活动中添加此代码。欢迎。如果这解决了你的问题,考虑接受答案。单击左侧的勾号。将鼠标悬停,它将出现。大家好,此代码仅适用于移动设备中没有国家代码的号码,但如果我尝试使用带有国家代码的号码,则其不起作用,而对于国际邮件,我的意思是如何发送国际邮件?欢迎。如果这解决了你的问题,考虑接受答案。单击左侧的勾号。将鼠标悬停,它会出现。大家好,此代码仅适用于移动设备中没有国家代码的号码,但如果我尝试使用带有国家代码的号码,则其不起作用,而对于国际邮件,我的意思是如何发送国际邮件?