1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| @SuppressWarnings({ "deprecation", "deprecation" })
public void sendSMS(String message, String phoneNumber)
{
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
ArrayList<PendingIntent> sentPendingIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveredPendingIntents = new ArrayList<PendingIntent>();
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
registerReceiver(new BroadcastReceiver() {
@SuppressWarnings("deprecation")
@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
switch(getResultCode())
{
case Activity.RESULT_OK:
display("SUCCES:TRANSFERT VALIDE.");
mp_smssend.start();//jouer un sont d'envoi reussi !
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
display("Generic failure");
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
display("No Service");
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
display("Null PDU");
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
display("Radio off");
break;
}
}
}, new IntentFilter(SENT));
registerReceiver(new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
switch(getResultCode())
{
case Activity.RESULT_OK:
display("Merci et à bientot ");
break;
case Activity.RESULT_CANCELED:
display("Problème de réseau veuillez réessayer");
break;
}
}
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault() ;
ArrayList<String> msgStringArray = sms.divideMessage(message);
for (int number=0; number<msgStringArray.size();number++)
{
sentPendingIntents.add(sentPI);
deliveredPendingIntents.add(deliveredPI);
}
sms.sendMultipartTextMessage(phoneNumber, null, msgStringArray, sentPendingIntents, deliveredPendingIntents);
} |
Partager