List of usage examples for android.telephony SmsManager sendTextMessage
public void sendTextMessage(String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)
From source file:com.purdue.CampusFeed.Activities.ContactDetailFragment.java
@Override public void onClick(View v) { SmsManager sms = SmsManager.getDefault(); String URL = getString(R.string.redirection_url) + myEvent.getId(); String message = "I would like to invite you, my friend, to " + myEvent.getEventName() + ". This is the link: " + URL; sms.sendTextMessage(this.contactPhoneNumber, null, message, null, null); Context context = getActivity(); CharSequence text = "Invite Sent!"; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show();//w ww. j a v a2s . c o m }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Sends SMS Alarms to the telephone numbers specified in mSMSNumbers[] *//*www. ja va2 s .c o m*/ public void sendSMSAlarm() { if (mSMSAlarm) { Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers.length + " Numbers"); Time tnow = new Time(Time.getCurrentTimezone()); tnow.setToNow(); String dateStr = tnow.format("%Y-%m-%d %H-%M-%S"); SmsManager sm = SmsManager.getDefault(); for (int i = 0; i < mSMSNumbers.length; i++) { Log.v(TAG, "sendSMSAlarm() - Sending to " + mSMSNumbers[i]); sm.sendTextMessage(mSMSNumbers[i], null, mSMSMsgStr + " - " + dateStr, null, null); } } else { Log.v(TAG, "sendSMSAlarm() - SMS Alarms Disabled - not doing anything!"); Toast toast = Toast.makeText(getApplicationContext(), "SMS Alarms Disabled - not doing anything!", Toast.LENGTH_SHORT); toast.show(); } }
From source file:com.yangtsaosoftware.pebblemessenger.services.PebbleCenter.java
public void doSendSMSTo(String phoneNumber, String message) { if (PhoneNumberUtils.isGlobalPhoneNumber(phoneNumber)) { SmsManager smsmanager = SmsManager.getDefault(); ArrayList<String> smsList = smsmanager.divideMessage(message); for (String sms : smsList) { smsmanager.sendTextMessage(phoneNumber, null, sms, null, null); }/*from w ww .j a va 2s . c o m*/ Constants.log("sendsms", String.format("send:[%s] to number:%s", message, phoneNumber)); } }
From source file:org.xwalk.runtime.extension.api.messaging.MessagingSmsManager.java
public void onSmsSend(int instanceID, JSONObject jsonMsg) { if (!checkService(DEFAULT_SERVICE_ID)) { Log.e(TAG, "No Sim Card"); return;/*from w ww. j a va 2 s.co m*/ } String promise_id = null; JSONObject eventBody = null; String phone = null; String smsMessage = null; try { promise_id = jsonMsg.getString("_promise_id"); eventBody = jsonMsg.getJSONObject("data"); phone = eventBody.getString("phone"); smsMessage = eventBody.getString("message"); } catch (JSONException e) { e.printStackTrace(); return; } SmsManager sms = SmsManager.getDefault(); Intent intentSmsSent = new Intent("SMS_SENT"); intentSmsSent.putExtra(EXTRA_MSGID, promise_id); intentSmsSent.putExtra(EXTRA_MSGTEXT, smsMessage); intentSmsSent.putExtra(EXTRA_MSGTO, phone); String instanceIDString = Integer.toString(instanceID); intentSmsSent.putExtra(EXTRA_MSGINSTANCEID, instanceIDString); int promiseIdInt = Integer.valueOf(promise_id); PendingIntent piSent = PendingIntent.getBroadcast(mMainActivity, promiseIdInt, intentSmsSent, PendingIntent.FLAG_ONE_SHOT); Intent intentSmsDelivered = new Intent("SMS_DELIVERED"); intentSmsDelivered.putExtra(EXTRA_MSGID, promise_id); intentSmsDelivered.putExtra(EXTRA_MSGTEXT, smsMessage); intentSmsDelivered.putExtra(EXTRA_MSGINSTANCEID, instanceIDString); PendingIntent piDelivered = PendingIntent.getBroadcast(mMainActivity, -promiseIdInt, intentSmsDelivered, PendingIntent.FLAG_ONE_SHOT); sms.sendTextMessage(phone, null, smsMessage, piSent, piDelivered); }
From source file:com.droid.app.fotobot.FotoBot.java
public void sendSMS(String phoneNumber, String message) { 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); //---when the SMS has been sent--- registerReceiver(new BroadcastReceiver() { @Override//from w ww. ja v a 2s .com public void onReceive(Context arg0, Intent arg1) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent", Toast.LENGTH_SHORT).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() { @Override public void onReceive(Context arg0, Intent arg1) { 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)); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); }
From source file:com.hhunj.hhudata.SearchBookContentsActivity.java
private void sendSMS(String phoneNumber, String message) { // ---sends an SMS message to another device--- SmsManager sms = SmsManager.getDefault(); String SENT_SMS_ACTION = "SENT_SMS_ACTION"; String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION"; // create the sentIntent parameter Intent sentIntent = new Intent(SENT_SMS_ACTION); PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0); // create the deilverIntent parameter Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION); PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0); // register the Broadcast Receivers registerReceiver(new BroadcastReceiver() { @Override//from www .j av a 2s.c om public void onReceive(Context _context, Intent _intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent success actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "SMS generic failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "SMS radio off failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "SMS null PDU failure actions", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SENT_SMS_ACTION)); registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context _context, Intent _intent) { Toast.makeText(getBaseContext(), "SMS delivered actions", Toast.LENGTH_SHORT).show(); } }, new IntentFilter(DELIVERED_SMS_ACTION)); // if message's length more than 70 , // then call divideMessage to dive message into several part ,and call // sendTextMessage() // else direct call sendTextMessage() if (message.length() > 70) { ArrayList<String> msgs = sms.divideMessage(message); for (String msg : msgs) { sms.sendTextMessage(phoneNumber, null, msg, sentPI, deliverPI); } } else { sms.sendTextMessage(phoneNumber, null, message, sentPI, deliverPI); } }
From source file:com.hhunj.hhudata.ForegroundService.java
private void sendSMS(String message) { if (message == "") return;//from ww w.ja v a 2 s. co m //String stext = " " +m_contactmap.size(); //notification ,title showNotification("hhudata", message); if (m_alarmInWorktime) {// Date dt = new Date(); if (IsDuringWorkHours(dt) == false) { return; } else { //alarm. } } if (message.length() > 140) { //.... return; } // ---sends an SMS message to another device--- SmsManager sms = SmsManager.getDefault(); String SENT_SMS_ACTION = "SENT_SMS_ACTION"; String DELIVERED_SMS_ACTION = "DELIVERED_SMS_ACTION"; // create the sentIntent parameter Intent sentIntent = new Intent(SENT_SMS_ACTION); PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, sentIntent, 0); // create the deilverIntent parameter Intent deliverIntent = new Intent(DELIVERED_SMS_ACTION); PendingIntent deliverPI = PendingIntent.getBroadcast(this, 0, deliverIntent, 0); // register the Broadcast Receivers registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context _context, Intent _intent) { switch (getResultCode()) { case Activity.RESULT_OK: Toast.makeText(getBaseContext(), "SMS sent success actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: Toast.makeText(getBaseContext(), "SMS generic failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_RADIO_OFF: Toast.makeText(getBaseContext(), "SMS radio off failure actions", Toast.LENGTH_SHORT).show(); break; case SmsManager.RESULT_ERROR_NULL_PDU: Toast.makeText(getBaseContext(), "SMS null PDU failure actions", Toast.LENGTH_SHORT).show(); break; } } }, new IntentFilter(SENT_SMS_ACTION)); registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context _context, Intent _intent) { Toast.makeText(getBaseContext(), "SMS delivered actions", Toast.LENGTH_SHORT).show(); } }, new IntentFilter(DELIVERED_SMS_ACTION)); // if message's length more than 70 , // then call divideMessage to dive message into several part ,and call // sendTextMessage() // else direct call sendTextMessage() Iterator it = m_contactmap.keySet().iterator(); while (it.hasNext()) { ContactColumn.ContactInfo info = m_contactmap.get(it.next()); if (info.mobile == null) continue; String mobile = info.mobile.trim(); if (mobile.length() >= 4) { if (message.length() > 70) { ArrayList<String> msgs = sms.divideMessage(message); for (String msg : msgs) { sms.sendTextMessage(mobile, null, msg, sentPI, deliverPI); } } else { sms.sendTextMessage(mobile, null, message, sentPI, deliverPI); } } } }