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.wordpress.jftreading.FragmentMain.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.update_contact: startActivityForResult(new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI), PICK_CONTACT_REQUEST);//from w w w . j a v a 2 s .c o m break; case R.id.call_btn: // Dial mobile number if (contactUri != null) { Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + getMobileNumber(contactUri))); startActivity(callIntent); } break; case R.id.send_btn: String stextMessage = textMessage.getText().toString(); if (stextMessage.matches("")) { } else if (contactUri != null) { dialog = ProgressDialog.show(getActivity(), "Sending", "Sending text message"); Thread th = new Thread(new Runnable() { @Override public void run() { // Send text message try { String SENT = "sent"; String DELIVERED = "delivered"; Intent sentIntent = new Intent(SENT); //Create Pending Intents PendingIntent sentPI = PendingIntent.getBroadcast(getActivity().getApplicationContext(), 0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent deliveryIntent = new Intent(DELIVERED); PendingIntent deliverPI = PendingIntent.getBroadcast( getActivity().getApplicationContext(), 0, deliveryIntent, PendingIntent.FLAG_UPDATE_CURRENT); //Register for SMS send action getActivity().registerReceiver(new BroadcastReceiver() { String result = ""; @Override public void onReceive(Context context, Intent intent) { switch (getResultCode()) { case Activity.RESULT_OK: result = "Message sent"; break; case SmsManager.RESULT_ERROR_GENERIC_FAILURE: result = "Sending failed"; break; case SmsManager.RESULT_ERROR_RADIO_OFF: result = "Radio off"; break; case SmsManager.RESULT_ERROR_NULL_PDU: result = "No PDU defined"; break; case SmsManager.RESULT_ERROR_NO_SERVICE: result = "No service"; break; } handler.post(new Runnable() { @Override public void run() { if (result != "") { Toast toast = Toast.makeText(getActivity().getApplicationContext(), result, Toast.LENGTH_LONG); toast.setGravity(Gravity.CENTER, 0, 0); toast.show(); result = ""; } dialog.dismiss(); } }); } }, new IntentFilter(SENT)); //Register for Delivery event getActivity().registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { handler.post(new Runnable() { @Override public void run() { Toast.makeText(getActivity().getApplicationContext(), "Delivered", Toast.LENGTH_LONG).show(); } }); } }, new IntentFilter(DELIVERED)); //Send SMS SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(getMobileNumber(contactUri), null, textMessage.getText().toString(), sentPI, deliverPI); } catch (Exception ex) { final String exception = ex.getMessage().toString(); handler.post(new Runnable() { @Override public void run() { Toast.makeText(getActivity().getApplicationContext(), exception, Toast.LENGTH_LONG).show(); } }); ex.printStackTrace(); dialog.dismiss(); } } }); th.start(); } break; default: break; } }
From source file:org.protocoderrunner.apprunner.api.PDevice.java
@ProtoMethod(description = "send an sms to the given number", example = "") @ProtoMethodParam(params = { "number", "message" }) public void smsSend(String number, String msg) { SmsManager sm = SmsManager.getDefault(); sm.sendTextMessage(number, null, msg, null, null); }
From source file:com.winsuk.pebbletype.WatchCommunication.java
public void receiveData(final Context context, final int transactionId, final PebbleDictionary data) { PebbleKit.sendAckToPebble(context, transactionId); if (data.contains(KEY_REQUEST_THREAD_LIST)) { sendThreadList(context);/* w w w . j av a2s.co m*/ } if (data.contains(KEY_SEND_MESSAGE)) { String str = data.getString(KEY_SEND_MESSAGE); boolean demoMode = str.startsWith(";"); String address = str.substring(0, str.indexOf(";")); String message = str.substring(str.indexOf(";") + 1, str.length()); if (!demoMode) { SmsManager sms = SmsManager.getDefault(); // Tried to use getService here which makes more sense, but that didn't work PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(ACTION_SMS_REPLY), PendingIntent.FLAG_ONE_SHOT); sms.sendTextMessage(address, null, message, pi, null); } } }
From source file:ca.hoogit.hooold.Scheduling.Sms.java
public void single(Context context, SmsManager manager, String recipient, int count) { Intent sent = generateIntent(Consts.INTENT_SMS_SENT, recipient, count); PendingIntent pendingSent = PendingIntent.getBroadcast(context, (int) id, sent, PendingIntent.FLAG_CANCEL_CURRENT); Intent delivered = generateIntent(Consts.INTENT_SMS_DELIVERED, recipient, count); PendingIntent pendingDelivered = PendingIntent.getBroadcast(context, (int) id, delivered, PendingIntent.FLAG_CANCEL_CURRENT); manager.sendTextMessage(recipient, null, messageBody, pendingSent, pendingDelivered); }
From source file:com.tbay.android.FrequentSMS.MainActivity.java
public void sendSMS(View view) { EditText Txt = (EditText) findViewById(R.id.SMSText); RadioGroup rg = (RadioGroup) findViewById(R.id.whichSMS); int rbid = rg.getCheckedRadioButtonId(); SmsManager smsManager = SmsManager.getDefault(); switch (rbid) { case R.id.Wifi: mAppPrefs.Key1_Msg = Txt.getText().toString(); mAppPrefs.SelectionId = 0;//from w ww. java 2 s. co m smsManager.sendTextMessage(AppConstants.phoneWifi, null, mAppPrefs.Key1_Msg, null, null); break; case R.id.Aftensmad: mAppPrefs.Key2_Msg = Txt.getText().toString(); mAppPrefs.SelectionId = 1; smsManager.sendTextMessage(AppConstants.phoneAnnette, null, mAppPrefs.Key2_Msg, null, null); break; case R.id.Snart_hjemme: mAppPrefs.Key3_Msg = Txt.getText().toString(); mAppPrefs.SelectionId = 2; smsManager.sendTextMessage(AppConstants.phoneAnnette, null, mAppPrefs.Key3_Msg, null, null); break; case R.id.TestSMS: mAppPrefs.Key4_Msg = Txt.getText().toString(); mAppPrefs.SelectionId = 3; smsManager.sendTextMessage(AppConstants.phonePrivate, null, mAppPrefs.Key4_Msg, null, null); break; } mAppPrefs.savePreferences(getApplicationContext()); }
From source file:com.ti.sensortag.gui.services.ServicesActivity.java
protected void sendSMSMessage(String value, String patient) { /*//from w ww .ja va 2 s. com String SENT = "sent."; String DELIVERED = "delivered."; Intent sentIntent = new Intent(SENT); //Create Pending Intents PendingIntent sentPI = PendingIntent.getBroadcast( getApplicationContext(), 0, sentIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent deliveryIntent = new Intent(DELIVERED); PendingIntent deliverPI = PendingIntent.getBroadcast( getApplicationContext(), 0, deliveryIntent, PendingIntent.FLAG_UPDATE_CURRENT);*/ Log.i("Send SMS", ""); String phoneNo = "09740370321"; long timi22 = System.currentTimeMillis(); //timi22 = timi22 - 19800000; String timi222 = String.valueOf(timi22); //String msgc = String.format("%04d", count); //String patient = "rsp"; try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNo, null, '&' + patient + '$' + timi22 + ' ' + value + '%', null, null); Toast.makeText(getApplicationContext(), "Sms sent.", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(getApplicationContext(), "Sms failed, please try again.", Toast.LENGTH_LONG).show(); e.printStackTrace(); } choice = 0; return; }
From source file:in.codehex.arrow.MainActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case Config.REQUEST_SPEECH_INPUT: if (resultCode == RESULT_OK && data != null) { ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); if (result.get(0).equalsIgnoreCase("emergency")) { String phone = userPreferences.getString(Config.KEY_PREF_PHONE, null); String message = "Emergency!\n" + userPreferences.getString(Config.KEY_PREF_NAME, null) + " is at http://maps.google.com/maps?q=" + lat + "," + lng; try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phone, null, message, null, null); textToSpeech.speak("Emergency alert sent!", TextToSpeech.QUEUE_FLUSH, null, null); } catch (Exception e) { textToSpeech.speak("Unable to send alert message!", TextToSpeech.QUEUE_FLUSH, null, null); }/* w w w . j a v a 2s .c o m*/ } else if (isDestinationAvailable) { if (result.get(0).equalsIgnoreCase("yes")) { processDirection(); isDestinationAvailable = false; } else { textToSpeech.speak(getString(R.string.prompt_speech_input_initial), TextToSpeech.QUEUE_FLUSH, null, Config.UTTERANCE_ID_INITIAL); isDestinationAvailable = false; } } else { speakData(result.get(0)); } } break; case Config.REQUEST_CHECK_TTS: if (resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(intent); } break; } }
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult sendSMS(JSONArray addressList, String text, CallbackContext callbackContext) { Log.d(LOGTAG, ACTION_SEND_SMS);// w w w . j a va 2 s. co m if (this.cordova.getActivity().getPackageManager().hasSystemFeature("android.hardware.telephony")) { int n; if ((n = addressList.length()) > 0) { PendingIntent sentIntent = PendingIntent.getBroadcast((Context) this.cordova.getActivity(), (int) 0, (Intent) new Intent("SENDING_SMS"), (int) 0); SmsManager sms = SmsManager.getDefault(); for (int i = 0; i < n; ++i) { String address; if ((address = addressList.optString(i)).length() <= 0) continue; sms.sendTextMessage(address, null, text, sentIntent, (PendingIntent) null); } } else { PendingIntent sentIntent = PendingIntent.getActivity((Context) this.cordova.getActivity(), (int) 0, (Intent) new Intent("android.intent.action.VIEW"), (int) 0); Intent intent = new Intent("android.intent.action.VIEW"); intent.putExtra("sms_body", text); intent.setType("vnd.android-dir/mms-sms"); try { sentIntent.send(this.cordova.getActivity().getApplicationContext(), 0, intent); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "OK")); } else { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "SMS is not supported")); } return null; }
From source file:com.trigger_context.Main_Service.java
private void takeAction(String mac, InetAddress ip) { noti("comes to ", mac); SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE); Map<String, ?> cond_map = conditions.getAll(); Set<String> key_set = cond_map.keySet(); Main_Service.main_Service.noti(cond_map.toString(), ""); if (key_set.contains("SmsAction")) { String number = conditions.getString("SmsActionNumber", null); String message = conditions.getString("SmsActionMessage", null); try {/* w w w. java 2s .c o m*/ SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(number, null, message, null, null); noti("Sms Sent To : ", "" + number); } catch (Exception e) { noti("Sms Sending To ", number + "Failed"); } } if (key_set.contains("OpenWebsiteAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Open_Url.class); dialogIntent.putExtra("urlAction", (String) cond_map.get("urlAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("ToggleAction")) { if (key_set.contains("bluetoothAction") && conditions.getBoolean("bluetoothAction", false)) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.enable(); } else if (key_set.contains("bluetoothAction")) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.disable(); } if (key_set.contains("wifiAction") && conditions.getBoolean("wifiAction", false)) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(true); } else if (key_set.contains("wifiAction")) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(false); } } if (key_set.contains("TweetAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Post_Tweet.class); dialogIntent.putExtra("tweetTextAction", (String) cond_map.get("tweetTextAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("EmailAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Email_Client.class); dialogIntent.putExtra("toAction", (String) cond_map.get("toAction")); dialogIntent.putExtra("subjectAction", (String) cond_map.get("subjectAction")); dialogIntent.putExtra("emailMessageAction", (String) cond_map.get("emailMessageAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("RemoteServerCmd")) { String text = conditions.getString("cmd", null); new Thread(new SendData("224.0.0.1", 9876, text)).start(); } // network activities from here. // in all network actions send username first if (key_set.contains("FileTransferAction")) { String path = conditions.getString("filePath", null); SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 1 try { Socket socket = new Socket(ip, COMM_PORT); DataOutputStream out = null; out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(1); sendFile(out, path); noti("Sent " + path + " file to :", getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (key_set.contains("ccfMsgAction")) { String msg = conditions.getString("ccfMsg", null); SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 2 is msg try { Socket socket = new Socket(ip, COMM_PORT); DataOutputStream out = null; out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(2); out.writeUTF(msg); noti("Sent msg : '" + msg + "'", "to : " + getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (key_set.contains("sync")) { SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 3 is sync try { Socket socket = new Socket(ip, COMM_PORT); DataInputStream in = new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(3); senderSync(in, out, Environment.getExternalStorageDirectory().getPath() + "/TriggerSync/"); noti("Synced with:", getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.dileepindia.cordova.sms.SMSPlugin.java
public void sendSMS(String phoneNumber, String message) { SmsManager manager = SmsManager.getDefault(); PendingIntent sentIntent = PendingIntent.getActivity(activity, 0, new Intent(), 0); PendingIntent deliveryIntent = PendingIntent.getActivity(activity, 0, new Intent(), 0); manager.sendTextMessage(phoneNumber, null, message, sentIntent, null); }