Android Open Source - Android-Universal-Notifier S M S Sender

From Project

Back to project page Android-Universal-Notifier.


The source code is released under:

Apache License

If you think the Android project Android-Universal-Notifier listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

//from w ww .  j  a v  a  2 s  .com
import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.util.Log;

public class SMSSender {

  public static final String SMS_SENT = "SMS_SENT";
  public static final String SMS_DELIVERED = "SMS_DELIVERED";
  public static void sendSMS(String f_phoneNumber, String f_message, int f_rc, Context f_context){
    SmsManager smsManager = SmsManager.getDefault();
    ArrayList<String> parts = smsManager.divideMessage(f_message);
        int messageCount = parts.size();

        Log.i("Message Count", "Message Count: " + messageCount);

        ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();
        ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
        PendingIntent sentPI = PendingIntent.getBroadcast(f_context, f_rc, new Intent(SMS_SENT).putExtra("phoneNumber", f_phoneNumber), 0);
        PendingIntent deliveredPI = PendingIntent.getBroadcast(f_context, f_rc, new Intent(SMS_DELIVERED).putExtra("phoneNumber", f_phoneNumber), 0);

        for (int j = 0; j < messageCount; j++) {
        smsManager.sendTextMessage(f_phoneNumber, null, f_message, sentPI, deliveredPI);

Java Source Code List