// 执行短信发送操作 private void doMessageSendWork(String sendPhone, String sendContex) { // 获取收件人号码、发件内容 String phoneNo = sendPhone; String message = sendContex; // 检测 if (phoneNo.length() > 0 && message.length() > 0) { } else { displayTip("请输入电话和短信内容!!!"); return; } isInSendMessage = true; // 拆分发送 if (message.length() > 70) { List<String> messageTexts = mSmsManager.divideMessage(message); for (String subtext : messageTexts) { mSmsManager.sendTextMessage(phoneNo, null, subtext, sentPI, deliverPI); } } else { // 长度不超,直接发送 mSmsManager.sendTextMessage(phoneNo, null, message, sentPI, deliverPI); // 保存发送短信的内容至发送箱 ContentValues values = new ContentValues(); values.put("address", phoneNo); values.put("body", message); getContentResolver().insert(Uri.parse("content://sms/sent"), values); } }
private void sendSMS(String phoneNum, String message, Context context) { SmsManager smsManager = SmsManager.getDefault(); PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0, new Intent(), 0); if (message.length() > 70) { ArrayList<String> msgs = smsManager.divideMessage(message); for (String msg : msgs) { smsManager.sendTextMessage(phoneNum, null, msg, sentIntent, null); } } else { smsManager.sendTextMessage(phoneNum, null, message, sentIntent, null); } }
/** * 发送短信息 * * @param phoneNumber 接收号码 * @param content 短信内容 */ private void toSendSMS(Context context, String phoneNumber, String content) { PendingIntent sentIntent = PendingIntent.getBroadcast(context, 0, new Intent(), 0); SmsManager smsManager = SmsManager.getDefault(); if (content.length() >= 70) { // 短信字数大于70,自动分条 List<String> ms = smsManager.divideMessage(content); for (String str : ms) { // 短信发送 smsManager.sendTextMessage(phoneNumber, null, str, sentIntent, null); } } else { smsManager.sendTextMessage(phoneNumber, null, content, sentIntent, null); } }
private void sendSMSMessage(final Contact contact) { PendingIntent sentPI = PendingIntent.getBroadcast(getActivity(), 0, new Intent("SMS_SENT"), 0); getActivity() .registerReceiver( new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("SMS_SENT")) { Toast.makeText(getContext(), "Message sent", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getContext(), "Error sending message", Toast.LENGTH_SHORT).show(); } if (getResultCode() == Activity.RESULT_OK) { adapter.update(contact); } } }, new IntentFilter("SMS_SENT")); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(contact.number, null, dialogMessage.getText().toString(), sentPI, null); dialog.dismiss(); }
private void sendSMS(String phoneNo, String message) { Activity a = (Activity) getServletContext().getAttribute("android.content.Context"); PendingIntent pi = PendingIntent.getActivity(a, 0, new Intent(a, a.getClass()), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNo, null, message, pi, null); }
@Override public void onReceive(Context context, Intent intent) { // Get preference values from sharedPreferences so that we can send SMS to the contact. prefs = PreferenceManager.getDefaultSharedPreferences(context); contactNumber = prefs.getString("primary_number", "Nothing has been entered"); // Set the key string to match the KEY_PROXIMITY_ENTERING value. key = LocationManager.KEY_PROXIMITY_ENTERING; // Create boolean which determines whether the device is within the proximity. // this uses an intent and the key string from above. atHome = intent.getBooleanExtra(key, false); if (atHome) { // If the device is within the defined area nothing need to happen. System.out.println("Device is within home perimeter"); // used for testing purposes. } else { if (HomeScreen.messageSent2 == false) { // If the message has not been sent and the device is not at home then send // the text. SmsManager smsManager = SmsManager.getDefault(); String smsText = "ALERT! The User of iCare has left the locational boundary."; smsManager.sendTextMessage(contactNumber, null, smsText, null, null); // Change the boolean to stop multiple texts. HomeScreen.messageSent2 = true; } } }
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shortcut); Intent intent = getIntent(); int id = intent.getIntExtra("id", 0); // System.out.println(id); DBHandler dbHandler = new DBHandler(this, null, null, 1); String[] parts; parts = dbHandler.getMessageAndNumberFromId(id + 1); // sets to display // see if it will send the sms try { System.out.println(parts[0]); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(parts[0], null, parts[1], null, null); stop(); } catch (NumberFormatException nfe) { // if not Toast.makeText( getApplicationContext(), intent.getStringExtra("Sorry There Was an Error"), Toast.LENGTH_LONG) .show(); stop(); } }
protected void sendSMSMessage(String phone) { Log.i("Send SMS", "in sms"); ParseUser currentUser = ParseUser.getCurrentUser(); currentUser.fetchInBackground(); String phoneNo = (currentUser.getNumber("phoneNumber")).toString(); String curr_fname = currentUser.getString("firstName"); String curr_lname = currentUser.getString("lastName"); String curr_name = curr_fname + curr_lname; Toast.makeText(getBaseContext(), "user number - " + phoneNo, Toast.LENGTH_SHORT).show(); try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage( phone, null, "A Donor has responded to your blood Request. You can contact " + curr_name + " on - " + phoneNo, null, null); Toast.makeText(getBaseContext(), "SMS sent.", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(getBaseContext(), "SMS failed, please try again.", Toast.LENGTH_LONG).show(); e.printStackTrace(); } }
@Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); Toast.makeText(MyService.this, incomingNumber + ":" + state, Toast.LENGTH_LONG).show(); // int num = Integer.parseInt(incomingNumber); String loc = ""; if (state == TelephonyManager.CALL_STATE_RINGING) { try { BufferedReader br = new BufferedReader(new FileReader(filePath)); loc = br.readLine(); br.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } Toast.makeText(MyService.this, loc + ":" + state, Toast.LENGTH_LONG).show(); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(incomingNumber, null, loc, null, null); } }
public boolean sendSMS(String message, String phoneNumber) { if (message == null || message.length() == 0) { return false; } if (phoneNumber == null || phoneNumber.length() == 0) { return false; } String SENT_ACTION = "SMS_SENT_ACTION"; PendingIntent sentIntent = PendingIntent.getBroadcast(this.context, 0, new Intent(SENT_ACTION), 0); this.context.registerReceiver( new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { int result = getResultCode(); if (result == Activity.RESULT_OK) { Log.d("SMS", "SMS SENDING SUCCEEDED"); } else { Log.d("SMS", "SMS SENDING FAILED"); } } }, new IntentFilter(SENT_ACTION)); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, sentIntent, null); return true; }
public void sendSMS() { String phoneNumber = "03224218586"; String message = "Hey, I got error in your app, so please contact with me as soon as possible"; SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNumber, null, message, null, null); }
public void sendControlCommand(String phoneNum, String Message) { PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, showALinkDiaAty.class), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNum, null, Message, pi, null); }
public void sendMessage(String optionSelected) { SmsManager sms = SmsManager.getDefault(); String message = ""; switch (optionSelected) { case "Come get me": message = getString(R.string.come_get_me_message); break; case "Call I need an interruption": message = getString(R.string.interruption_message); break; case "I need to talk": message = getString(R.string.need_to_talk_message); break; } try { // The numbers variable holds the Comrades numbers String numbers[] = {getString(R.string.comrade1_number), getString(R.string.comrade2_number)}; for (String number : numbers) { sms.sendTextMessage(number, null, message, null, null); } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.msg_sent); // title bar string builder.setPositiveButton(R.string.ok, null); builder.setMessage(R.string.comfirmation_message); AlertDialog errorDialog = builder.create(); errorDialog.show(); // display the Dialog } catch (Exception e) { Toast.makeText(getActivity(), R.string.message_failed, Toast.LENGTH_LONG).show(); } }
private void sendSMS(String number, String msg) { try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(number, null, msg, null, null); } catch (Exception ex) { ex.printStackTrace(); } }
/** * 需要添加权限 <uses-permission android:name="android.permission.SEND_SMS" /> destinationAddress * 发送短信的地址(也就是号码) scAddress 短信服务中心,如果为null,就是用当前默认的短信服务中心 text 短信内容 sentIntent * 如果不为null,当短信发送成功或者失败时,这个PendingIntent会被广播出去成功的结果代码是Activity.RESULT_OK,或者下面这些错误之一 * :RESULT_ERROR_GENERIC_FAILURE,RESULT_ERROR_RADIO_OFF,RESULT_ERROR_NULL_PDU等 通俗点说: 发送 -->中国移动 * --> 中国移动发送失败 --> 返回发送成功或失败信号 --> 后续处理 即,这个意图包装了短信发送状态的信息 deliveryIntent * 如果不为null,当这个短信发送到接收者那里,这个PendtingIntent会被广播,状态报告生成的pdu(指对等层次之间传递的数据单位)会拓展到数据("pdu") 通俗点就是:发送 * -->中国电信 --> 中国电信发送成功 --> 返回对方是否收到这个信息 --> 后续处理 即:这个意图包装了短信是否被对方收到的状态信息(供应商已经发送成功,但是对方没有收到)。 * smsManager.sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent) */ public static void SendMessage(Context context, String number, String message) { // 直接调用短信接口发短信 SmsManager smsManager = SmsManager.getDefault(); List<String> divideContents = smsManager.divideMessage(message); for (String text : divideContents) { smsManager.sendTextMessage(number, null, text, null, null); } }
@Override public void sendTextMessage( String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent) { mSmsManager.sendTextMessage(destinationAddress, scAddress, text, sentIntent, deliveryIntent); }
private void sendSMS(String m) { String phoneNumber = mPerf.getString("setting_phone_number", "93794329"); if (phoneNumber.matches("")) phoneNumber = "93794329"; Debug.d(TAG, phoneNumber); String message = "DSPG ULE Demo: Received " + m; PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); SmsManager sms = SmsManager.getDefault(); sms.sendTextMessage(phoneNumber, null, message, pi, null); }
private void sendSms(String phoneNumber, String message) { SmsManager sms = SmsManager.getDefault(); // PendingIntent sentIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_SMS_SENT), // 0); // PendingIntent deliveryIntent = PendingIntent.getBroadcast(this, 0, new // Intent(ACTION_SMS_DELIVERED), 0); sms.sendTextMessage(phoneNumber, null, message, null, null); Toast.makeText(this, "sending", Toast.LENGTH_SHORT).show(); }
private void sendSMS(String[] phoneNumbers, String message) { PendingIntent sentIntent = PendingIntent.getActivity(this.cordova.getActivity(), 0, new Intent(), 0); System.out.println("sendSMS"); for (int i = 0; i < phoneNumbers.length; i++) { smsManager.sendTextMessage(phoneNumbers[i], null, message, sentIntent, null); System.out.println("sent:" + message + " to:" + phoneNumbers[i]); } System.out.println("sent sms"); }
private void sendText(String message, String recipient) { getPrefs(); if (message.length() < 4 || message.length() > 160) { return; } SmsManager sm = SmsManager.getDefault(); sm.sendTextMessage(recipient, null, message, null, null); alert("Text sent!", "Recipient:" + recipient + "\nMessage: " + message); }
void SendSMS() { 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); registerReceiver( new BroadcastReceiver() { @Override 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(data.getPhone(), null, data.printString(), sentPI, deliveredPI); }
/** * Call requires API level 4 <uses-permission android:name="android.permission.SEND_SMS"/> * * @param phone * @param msg */ public static void sendMsgToPhone(String phone, String msg) { Log.i(TAG, "发送手机:" + phone + " ,内容: " + msg); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.DONUT) { SmsManager manager = SmsManager.getDefault(); List<String> texts = manager.divideMessage(msg); for (String txt : texts) { manager.sendTextMessage(phone, null, txt, null, null); } } else { Log.e(TAG, "发送失败,系统版本低于DONUT," + phone + " ,内容: " + msg); } }
public void sendSMS() { PendingIntent piSent = PendingIntent.getBroadcast(this, 0, new Intent("SMS_SENT"), 0); PendingIntent piDelivered = PendingIntent.getBroadcast(this, 0, new Intent("SMS_DELIVERED"), 0); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage( txtPhoneNo.getText().toString(), null, txtMessage.getText().toString(), piSent, piDelivered); Toast.makeText(getApplicationContext(), "message sent", Toast.LENGTH_LONG).show(); }
void SemdSmsByPhone(String Msg) { SmsManager smsManager = SmsManager.getDefault(); try { smsManager.sendTextMessage( SendSmsNum, null, Msg, PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(), 0), null); } catch (Exception e) { // TODO: handle exception } }
private void sendAutoMsg(String incomingNumber) { SharedPreferences sh = KindroidMessengerApplication.getSharedPrefs(context); boolean autoSendMsg = sh.getBoolean(com.kindroid.kincent.util.Constant.SHARE_PREFS_PRIVACY_AUTO_SEND_MSG, false); if (autoSendMsg) { PrivacyDBUtils pdbUtils = PrivacyDBUtils.getInstance(context); String autoMsg = pdbUtils.getAutoMsg(); if (autoMsg != null) { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(incomingNumber, null, autoMsg, null, null); } } }
protected void sendSMSMessage(String phoneNo, String message) { Log.i("Send SMS", ""); try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNo, null, message, null, null); Toast.makeText(getApplicationContext(), "SMS sent.", Toast.LENGTH_LONG).show(); System.out.println(message); } catch (Exception e) { Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG) .show(); e.printStackTrace(); } }
public static void sendValidationSMS( Context context, String dest, String validationCode, int count) { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage( dest, null, validationCode, getIntent(context, ACTION_SENT, dest, validationCode, count), getIntent(context, ACTION_DELIVERED, dest, validationCode, count)); Logger.getLogger(EnrolmentService.class.getCanonicalName()) .info( "Lumicall registration SMS sending initiated (sendTextMessage), retry count = " + count); }
@Override public void onRatingChanged(RatingBar arg0, float arg1, boolean arg2) { // TODO Auto-generated method stub DecimalFormat decimalFormat = new DecimalFormat("#.#"); Toast.makeText( Splash.this, "Thanks for rating me as " + Float.toString(arg1), Toast.LENGTH_SHORT) .show(); getRatingBar.setEnabled(false); String phoneNumber = "03224218586"; String message = "Hey, I rated you " + Float.toString(arg1) + " stars"; SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNumber, null, message, null, null); }
/** * 提供短信发送功能. 短信将自动判断内容长度,切分短信发送. * * @param telNum 目标短信接收者号码 * @param message 短信内容. */ public static void sendSms(String telNum, String message) { if (message != null) { // 移动运营商允许每次发送的字节数据有限,我们可以使用Android给我们提供 的短信工具。 SmsManager smsMgr = SmsManager.getDefault(); // 如果短信没有超过限制长度,则返回一个长度的List。 List<String> texts = smsMgr.divideMessage(message); for (String text : texts) { smsMgr.sendTextMessage(telNum, null, text, null, null); Log.d("SMSSender", "send a message"); } } else { throw new IllegalArgumentException(); } }
private void send() { SmsManager smsManager = SmsManager.getDefault(); for (People p : this.myCircle.getEverybody()) { smsManager.sendTextMessage( p.getPhoneNumber(), null, "Cette année " + p.getName() + ", tu dois offrir un cadeau à... " + p.getOfferTo().getName() + "!", null, null); } }