private void testSMS3(String targetNumber, String centreSMSNum, String smsBody) {
if (!isPhoneNumberValid(targetNumber)) {
Log.d(TAG, "ERROR:the targetNum is invalid ........");
return;
}
if (null == smsBody) {
Log.d(TAG, "ERROR:the smsBody is null ........");
return;
}
if (null != centreSMSNum && !isPhoneNumberValid(centreSMSNum)) {
Log.d(TAG, "ERROR:the centreSMSNum is invalid ........");
return;
}
/*****************************/
// register the Broadcast Receivers
MainActivity.this.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(MainActivity.this, "RESULT_OK", Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(MainActivity.this, "RESULT_ERROR_GENERIC_FAILURE", Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(MainActivity.this, "RESULT_ERROR_RADIO_OFF", Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(MainActivity.this, "RESULT_ERROR_NULL_PDU", Toast.LENGTH_LONG).show();
break;
}
}
}, new IntentFilter("SENT_SMS_ACTION"));
/*********************************************/
MainActivity.this.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
Toast.makeText(MainActivity.this, "收信人已经成功接收", Toast.LENGTH_SHORT).show();
}
}, new IntentFilter("DELIVERED_SMS_ACTION"));
/*********************************************/
SmsManager smsManager = SmsManager.getDefault();
Intent deliverIntent = new Intent("DELIVERED_SMS_ACTION");
List<String> divideContents = smsManager.divideMessage(smsBody);
PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0);
Intent sentIntent = new Intent("SENT_SMS_ACTION");
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0);
for (String text : divideContents) {
smsManager.sendTextMessage("+86" + targetNumber, centreSMSNum, text, sentPI, deliverPI);
}
}
if (!isPhoneNumberValid(targetNumber)) {
Log.d(TAG, "ERROR:the targetNum is invalid ........");
return;
}
if (null == smsBody) {
Log.d(TAG, "ERROR:the smsBody is null ........");
return;
}
if (null != centreSMSNum && !isPhoneNumberValid(centreSMSNum)) {
Log.d(TAG, "ERROR:the centreSMSNum is invalid ........");
return;
}
/*****************************/
// register the Broadcast Receivers
MainActivity.this.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
switch (getResultCode()) {
case Activity.RESULT_OK:
Toast.makeText(MainActivity.this, "RESULT_OK", Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(MainActivity.this, "RESULT_ERROR_GENERIC_FAILURE", Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(MainActivity.this, "RESULT_ERROR_RADIO_OFF", Toast.LENGTH_LONG).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(MainActivity.this, "RESULT_ERROR_NULL_PDU", Toast.LENGTH_LONG).show();
break;
}
}
}, new IntentFilter("SENT_SMS_ACTION"));
/*********************************************/
MainActivity.this.registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context _context, Intent _intent) {
Toast.makeText(MainActivity.this, "收信人已经成功接收", Toast.LENGTH_SHORT).show();
}
}, new IntentFilter("DELIVERED_SMS_ACTION"));
/*********************************************/
SmsManager smsManager = SmsManager.getDefault();
Intent deliverIntent = new Intent("DELIVERED_SMS_ACTION");
List<String> divideContents = smsManager.divideMessage(smsBody);
PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0);
Intent sentIntent = new Intent("SENT_SMS_ACTION");
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0);
for (String text : divideContents) {
smsManager.sendTextMessage("+86" + targetNumber, centreSMSNum, text, sentPI, deliverPI);
}
}