這可能會幫助你
private void sendSMS(final String phoneNumber, String message,String messageID)
{
PendingIntent pi = PendingIntent.getActivity(this, 0,
new Intent(this, SM.class), 0);
pi.putExtras("messageID",messageID);
SmsManager sms = SmsManager.getDefault();
//sms.sendTextMessage(phoneNumber, null, message, pi, null);
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
//showMessage("sms has been sent with reusltcode "+getResultCode());
String id=arg1.getBundle().getExtras().getString("messageID");
//This will recognize your message
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent to "+phoneNumber,
Toast.LENGTH_LONG).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(){
public void onReceive(Context arg0, Intent arg1) {
showMessage("sms has been delivered with reusltcode "+getResultCode());
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));
}
我會說你所尋求的知識不在這裏 - 另一個地方可能是另一個地方owledge sink – KevinDTimm
你到現在爲止所嘗試過的。 –
Downvoting,因爲這不是一個問題,你顯然試圖通過垃圾郵件濫用SO的工作方式。 – Layke