List of usage examples for android.telephony SmsManager getDefault
public static SmsManager getDefault()
From source file:com.xortech.sender.SenderReceive.java
/** * METHOD TO SEND SMS TO TAGS IN THE DATABASE * @param action//from ww w . java2s. c o m */ public void SendToMyTags() { TagDatabaseHandler mytdb = new TagDatabaseHandler(context); ArrayList<MyTags> mytag_array_from_db = mytdb.Get_Tags(); for (int i = 0; i < mytag_array_from_db.size(); i++) { String tagMsg = null; String mobile = null; String secret = null; int enabled = 0; mobile = mytag_array_from_db.get(i).getMyTagPhoneNumber(); secret = mytag_array_from_db.get(i).getTagSecret(); enabled = mytag_array_from_db.get(i).getTagStatus(); System.out.println(mobile); if (enabled == 1) { tagMsg = SECRET_LOCATION_C + secret; SmsManager.getDefault().sendTextMessage(mobile, null, tagMsg, null, null); } } mytdb.close(); }
From source file:com.xortech.sender.SenderSend.java
/** * METHOD TO SEND DATA TO OUR PANIC NUMBERS * //w ww .java 2 s . c o m * @param msg * THIS VARIABLE RECEIVES THE STRING WE GENERATED IN THE GETCOORDINATES() METHOD AND * SENDS IT TO THE PHONE NUMBERS/EMAILS LOCATED IN OUR DATABASE * * */ public void SendToMyPanicNumbers(String msg) { PanicDatabaseHandler mytdb = new PanicDatabaseHandler(context); ArrayList<MyPanicNumbers> mytag_array_from_db = mytdb.Get_Numbers(); String sendMsg = msg; myList = new ArrayList<String>(); for (int i = 0; i < mytag_array_from_db.size(); i++) { String mobile = null; String email = null; int enabled = 0; int pEnabled = 0; int eEnabled = 0; mobile = mytag_array_from_db.get(i).getMyPanicPhoneNumber(); enabled = mytag_array_from_db.get(i).getPanicActive(); email = mytag_array_from_db.get(i).getMyPanicEmail(); switch (enabled) { case 1: pEnabled = mytag_array_from_db.get(i).getPanicActiveP(); eEnabled = mytag_array_from_db.get(i).getPanicActiveE(); if (enabled != 0 && pEnabled == 1 && eEnabled == 0) { SmsManager.getDefault().sendTextMessage(mobile, null, sendMsg, null, null); } else if (enabled != 0 && pEnabled == 1 && eEnabled == 1) { if (email != null || email != " " || email != "") { if (email.contains("@")) { myList.add(email); } } SmsManager.getDefault().sendTextMessage(mobile, null, sendMsg, null, null); } else if (enabled != 0 && pEnabled == 0 && eEnabled == 1) { if (email != null || email != " " || email != "") { myList.add(email); } } break; default: /** * DO NOTHING SINCE IT IS DISABLED! */ break; } } mytdb.close(); // SendEmail(myList); SendEmailTask task = new SendEmailTask(); task.execute(); }
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 om*/ 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:dk.spaceblog.thenicobomb.MainActivity.java
/** Called when the user clicks the Send button */ public void sendSMSMessage() { //Intent sentIntent = new Intent("SMS_SENT"); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(this.phoneNumber, null, this.textMessage, null, null); }
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/* w w w.j av a 2 s . 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.polyvi.xface.extension.messaging.XMessagingExt.java
/** * ??/*from w w w . j av a 2 s.c o m*/ * * @param app * app?app??????UI? * @param addr * ? * @param body * ? * @return ? */ private void sendSMS(String addr, String body) { String regularExpression = "[+*#\\d]+"; if (!addr.matches(regularExpression)) { throw new IllegalArgumentException("address must be digit,*,# or +"); } IntentFilter smsSendIntentFilter = new IntentFilter(SMS_SENT); genSendSMSBroadreceiver(); // ?? mContext.registerReceiver(mSendSMSBroadcastReceiver, smsSendIntentFilter); SmsManager manager = SmsManager.getDefault(); ArrayList<String> textList = manager.divideMessage(body); ArrayList<PendingIntent> smsSendPendingIntentList = genSMSPendingIntentList(textList); manager.sendMultipartTextMessage(addr, null, textList, smsSendPendingIntentList, null); PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT); result.setKeepCallback(true); mCallbackContext.sendPluginResult(result); }
From source file:com.polyvi.xface.extension.XMessagingExt.java
/** * ??/*from www . jav a2 s . c o m*/ * @param app app?app??????UI? * @param addr ? * @param body ? * @return ? */ private XExtensionResult sendSMS(XIWebContext webContext, String addr, String body) { String regularExpression = "[+*#\\d]+"; if (!addr.matches(regularExpression)) { throw new IllegalArgumentException("address must be digit,*,# or +"); } IntentFilter smsSendIntentFilter = new IntentFilter(SMS_SENT); genSendSMSBroadreceiver(); // ?? getContext().registerReceiver(mSendSMSBroadcastReceiver, smsSendIntentFilter); SmsManager manager = SmsManager.getDefault(); ArrayList<String> textList = manager.divideMessage(body); ArrayList<PendingIntent> smsSendPendingIntentList = genSMSPendingIntentList(textList); manager.sendMultipartTextMessage(addr, null, textList, smsSendPendingIntentList, null); XExtensionResult er = new XExtensionResult(Status.NO_RESULT); er.setKeepCallback(true); return er; }
From source file:uk.org.openseizuredetector.SdServer.java
/** * Sends SMS Alarms to the telephone numbers specified in mSMSNumbers[] *//* ww w .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.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 {//ww w . j av a 2s . co 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(); } } }