Example usage for android.telephony SmsManager sendTextMessage

List of usage examples for android.telephony SmsManager sendTextMessage

Introduction

In this page you can find the example usage for android.telephony SmsManager sendTextMessage.

Prototype

public void sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent,
        PendingIntent deliveryIntent) 

Source Link

Document

Send a text based SMS.

Usage

From source file:capstone.se491_phm.Alarm.java

public static void sendSMS(Context context) {
    String phoneNumber = PreferenceManager.getDefaultSharedPreferences(context)
            .getString(Constants.EMERGENCY_CONTACT, "");
    if (!"".equals(phoneNumber)) {
        String message = "Help I have fallen! Last know location: ";

        LocationMgr locMgr = new LocationMgr(context);
        message += locMgr.getLocationUrl();

        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, null, null);

        broadcast(alertBroadcastIntent, "SMS Sent");
    } else {//from   w w  w  .  ja v  a  2  s  . com
        broadcast(alertBroadcastIntent, "Unable to send SMS. Missing number.");
    }
}

From source file:com.king.base.util.SystemUtils.java

/**
 * ?//from  w w  w  .j a v a 2  s . c  o  m
 *
 * @param phoneNumber
 * @param msg
 *
 */
public static void sendSMS(String phoneNumber, String msg) {

    SmsManager sm = SmsManager.getDefault();

    List<String> msgs = sm.divideMessage(msg);

    for (String text : msgs) {
        sm.sendTextMessage(phoneNumber, null, text, null, null);
    }

}

From source file:edu.polyu.screamalert.SoundProcessing.java

private static void sendSMS() {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Exchanger.thisContext);
    Boolean enableSMS = prefs.getBoolean("enableSMS", false);
    String phoneNumber = prefs.getString("phoneNumber", null);
    TelephonyManager phoneMgr = (TelephonyManager) thisContext.getSystemService(Context.TELEPHONY_SERVICE);
    if (enableSMS == true && phoneNumber != null && phoneNumber.trim().length() > 0
            && phoneMgr.getSimState() != TelephonyManager.SIM_STATE_ABSENT) {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNumber, null, "Scream detected. Longitude: " + gps.getLongitude()
                + "; Latitude: " + gps.getLatitude() + ". Please try to contact the mobile user", null, null);
    }//from w  w w.j  av a2  s  .  c  o m
}

From source file:com.prey.actions.location.LocationThread.java

private void sendSMS(String phoneNumber, String message) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || (ActivityCompat.checkSelfPermission(ctx,
            Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_GRANTED)) {
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage(phoneNumber, null, message, null, null);
    }/*  w ww. j  a v a2  s .  c  o  m*/

}

From source file:com.phonegap.plugins.smsplugin.SmsPlugin.java

private void sendSMS(String phoneNumber, String message) {
    SmsManager manager = SmsManager.getDefault();
    manager.sendTextMessage(phoneNumber, null, message, null, null);
}

From source file:com.doomy.overflow.SendService.java

private void sendMessage(String myPhoneNumber, String myMessage) {

    try {/*w  w w . j a  va2s  .  c o  m*/
        SmsManager mSmsManager = SmsManager.getDefault();
        mSmsManager.sendTextMessage(myPhoneNumber, null, myMessage, null, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:io.autem.AutemGcmListenerService.java

/**
 * Called when message is received.//from  w w w. j a va 2  s .  c o m
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);

    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {
        // normal downstream message.
    }

    // [START_EXCLUDE]
    /**
     * Production applications would usually process the message here.
     * Eg: - Syncing with server.
     *     - Store message in local database.
     *     - Update UI.
     */

    /**
     * In some cases it may be useful to show a notification indicating to the user
     * that a message was received.
     */
    sendNotification(message);
    Gson gson = new Gson();
    try {
        AutemTextMessage autemTextMessage = gson.fromJson(message, AutemTextMessage.class);
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(autemTextMessage.getTo(), null, autemTextMessage.getMessage(), null, null);
    } catch (com.google.gson.JsonSyntaxException e) {
        Log.e(TAG, "Failed to parse message from Chrome: " + message, e);
    }
    // [END_EXCLUDE]
}

From source file:edu.cmu.plugins.SmsPlugin.java

private void sendSMS(String phoneNumber, String message) {
    SmsManager manager = SmsManager.getDefault();

    PendingIntent sentIntent = PendingIntent.getActivity(this.ctx, 0, new Intent(), 0);

    manager.sendTextMessage(phoneNumber, null, message, sentIntent, null);
}

From source file:com.phonegap.helloworld.SmsPlugin.java

private void SendSMS(String phoneNumber, String message) {
    SmsManager manager = SmsManager.getDefault();

    PendingIntent sentIntent = PendingIntent.getActivity(this.ctx.getContext(), 0, new Intent(), 0);

    manager.sendTextMessage(phoneNumber, null, message, sentIntent, null);
}

From source file:com.example.android.smsmessaging.MainActivity.java

/**
 * Defines a string (destinationAddress) for the phone number
 * and gets the input text for the SMS message.
 * Uses SmsManager.sendTextMessage to send the message.
 * Before sending, checks to see if permission is granted.
 *
 * @param view View (message_icon) that was clicked.
 *//*from  www .j  a v a 2  s. com*/
public void smsSendMessage(View view) {
    EditText editText = (EditText) findViewById(R.id.editText_main);
    // Set the destination phone number to the string in editText.
    String destinationAddress = editText.getText().toString();
    // Find the sms_message view.
    EditText smsEditText = (EditText) findViewById(R.id.sms_message);
    // Get the text of the sms message.
    String smsMessage = smsEditText.getText().toString();
    // Set the service center address if needed, otherwise null.
    String scAddress = null;
    // Set pending intents to broadcast
    // when message sent and when delivered, or set to null.
    PendingIntent sentIntent = null, deliveryIntent = null;
    // Check for permission first.
    checkForSmsPermission();
    // Use SmsManager.
    SmsManager smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage(destinationAddress, scAddress, smsMessage, sentIntent, deliveryIntent);
}