/** Return a Cursor containing just one message from the ICC. */
 private Cursor getSingleMessageFromIcc(String messageIndexString) {
   int messageIndex = -1;
   try {
     Integer.parseInt(messageIndexString);
   } catch (NumberFormatException exception) {
     throw new IllegalArgumentException("Bad SMS ICC ID: " + messageIndexString);
   }
   ArrayList<SmsMessage> messages;
   final SmsManager smsManager = SmsManager.getDefault();
   // Use phone id to avoid AppOps uid mismatch in telephony
   long token = Binder.clearCallingIdentity();
   try {
     messages = smsManager.getAllMessagesFromIcc();
   } finally {
     Binder.restoreCallingIdentity(token);
   }
   if (messages == null) {
     throw new IllegalArgumentException("ICC message not retrieved");
   }
   final SmsMessage message = messages.get(messageIndex);
   if (message == null) {
     throw new IllegalArgumentException("Message not retrieved. ID: " + messageIndexString);
   }
   MatrixCursor cursor = new MatrixCursor(ICC_COLUMNS, 1);
   cursor.addRow(convertIccToSms(message, 0));
   return withIccNotificationUri(cursor);
 }
示例#2
0
  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);
  }
示例#3
0
 private SmsManager getSmsManagerFor(int subscriptionId) {
   if (Build.VERSION.SDK_INT >= 22 && subscriptionId != -1) {
     return SmsManager.getSmsManagerForSubscriptionId(subscriptionId);
   } else {
     return SmsManager.getDefault();
   }
 }
  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();
    }
  }
示例#5
0
文件: Sms.java 项目: Ribeiro/alunoce2
  /**
   * Envia um SMS para o numero indicado Obs.: o numero pode ser o do proprio emulador, exemplo:
   * 5554
   *
   * @param context
   * @param numero
   * @param mensagem
   * @return
   */
  public static boolean enviarSms(Context context, String numero, String mensagem) {
    try {
      SmsManager smsManager = SmsManager.getDefault();

      // identifica a chamada
      PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, new Intent(), 0);

      // Divide a mensagem caso ultrapasse 160 caracteres
      ArrayList<String> messages = smsManager.divideMessage(mensagem);

      // Instancia uma lista de PendingIntent
      ArrayList<PendingIntent> pIntents = new ArrayList<PendingIntent>(messages.size());

      for (int i = 0; i < messages.size(); i++) {
        pIntents.add(pIntent);
      }

      // envia a mensagem binaria
      smsManager.sendMultipartTextMessage(numero, null, messages, pIntents, null);

      return true;

    } catch (Exception e) {
      Log.e(LOG_SMS, "Erro ao enviar sms: " + e.getMessage(), e);
      return false;
    }
  }
示例#6
0
  /**
   * Send generic SMS
   *
   * @param phoneNumber
   * @param message
   */
  public void sendSms(Context context, String phoneNumber, String message) {
    if (PhoneNumberUtils.isWellFormedSmsAddress(phoneNumber)) {
      String SENT = "SMS_SENT";
      String DELIVERED = "SMS_DELIVERED";

      PendingIntent sentPI =
          PendingIntent.getBroadcast(context.getApplicationContext(), 0, new Intent(SENT), 0);

      PendingIntent deliveredPI =
          PendingIntent.getBroadcast(context.getApplicationContext(), 0, new Intent(DELIVERED), 0);

      /* receive when the SMS has been sent */
      context.getApplicationContext().registerReceiver(SmsSendReceiver, new IntentFilter(SENT));

      /* receive when the SMS has been delivered */
      context
          .getApplicationContext()
          .registerReceiver(SmsDeliveredReceiver, new IntentFilter(DELIVERED));

      Log.d(Constants.TAG, "Sending SMS to " + phoneNumber + " with message: " + message);

      // TODO: make it a preference to switch between data sms and normal sms

      SmsManager smsManager = SmsManager.getDefault();
      smsManager.sendDataMessage(
          phoneNumber, null, Constants.DATA_SMS_PORT, message.getBytes(), sentPI, deliveredPI);
      // smsManager.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
    } else {
      mCryptoCallService.sendUpdateUiToHandler(R.string.status_destination_invalid);
    }
  }
  // 执行短信发送操作
  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);
    }
  }
示例#8
0
    @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);
      }
    }
示例#9
0
  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;
  }
示例#10
0
  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();
  }
示例#11
0
  /**
   * Sends a text message via SMS. No authentication required. This method is called only when the
   * UseGoogleVoice option is disabled.
   */
  private void sendViaSms() {
    Log.i(TAG, "Sending via built-in Sms");

    ArrayList<String> parts = smsManager.divideMessage(message);
    int numParts = parts.size();
    ArrayList<PendingIntent> pendingIntents = new ArrayList<PendingIntent>();
    for (int i = 0; i < numParts; i++)
      pendingIntents.add(PendingIntent.getBroadcast(activity, 0, new Intent(SENT), 0));

    // Receiver for when the SMS is sent
    BroadcastReceiver sendReceiver =
        new BroadcastReceiver() {
          @Override
          public synchronized void onReceive(Context arg0, Intent arg1) {
            try {
              handleSentMessage(arg0, null, getResultCode(), message);
              activity.unregisterReceiver(this);
            } catch (Exception e) {
              Log.e("BroadcastReceiver", "Error in onReceive for msgId " + arg1.getAction());
              Log.e("BroadcastReceiver", e.getMessage());
              e.printStackTrace();
            }
          }
        };
    // This may result in an error -- a "sent" or "error" message will be displayed
    activity.registerReceiver(sendReceiver, new IntentFilter(SENT));
    smsManager.sendMultipartTextMessage(phoneNumber, null, parts, pendingIntents, null);
  }
 /**
  * while receiving one sms, check the sms count to see whether it reaches the max count.
  *
  * @param threadId
  * @param context
  * @param flag indicate the operator (increase/decrease)
  * @return true if the count is less than the max size, otherwise false.
  */
 public void isFull(Long threadId, Context context, int flag) {
   try {
     ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
     if (phone != null) {
       if (phone.isTestIccCard()
           || (Integer.parseInt(SystemProperties.get("gsm.gcf.testmode", "0")) == 2)) {
         Log.d(TAG, "Now using test icc card...");
         if (flag == OP_FLAG_INCREASE) {
           if (get(threadId, context) >= THREAD_MAX_SIZE) {
             Log.d(TAG, "Storage is full. send notification...");
             SmsManager.getDefault().setSmsMemoryStatus(false);
           }
         } else if (flag == OP_FLAG_DECREASE) {
           if (get(threadId, context) < THREAD_MAX_SIZE) {
             Log.d(TAG, "Storage is available. send notification...");
             SmsManager.getDefault().setSmsMemoryStatus(true);
           }
         }
       }
     } else {
       Log.d(TAG, "Telephony service is not available!");
     }
   } catch (Exception ex) {
     Log.e(TAG, " " + ex.getMessage());
   }
 }
示例#13
0
  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;
      }
    }
  }
示例#15
0
  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();
    }
  }
示例#16
0
  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);
  }
示例#17
0
  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();
    }
  }
 public static void sendSms(String address, byte[] data) {
   short SMS_PORT = 8998;
   SmsManager smsManager = SmsManager.getDefault();
   smsManager.sendDataMessage(
       address, null, // TODO: define scAddress if needed
       SMS_PORT, data, null, // TODO: define sentIntent if needed
       null); // TODO: define deliveryIntent if needed
 }
 private void sendSMS(String number, String msg) {
   try {
     SmsManager smsManager = SmsManager.getDefault();
     smsManager.sendTextMessage(number, null, msg, null, null);
   } catch (Exception ex) {
     ex.printStackTrace();
   }
 }
示例#20
0
 /**
  * 需要添加权限 <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);
   }
 }
 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();
 }
示例#22
0
 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);
 }
示例#23
0
  public void send(String phoneNumber, String messageToSent) {

    PhoneNumber number = PhoneNumber.parse(phoneNumber);

    SmsManager sms = SmsManager.getDefault();
    System.out.println("Sending SMS to: " + phoneNumber + ", message: " + messageToSent);

    ArrayList<String> messageArray = sms.divideMessage(messageToSent);
    sms.sendMultipartTextMessage(number.getPhoneNumber(), null, messageArray, null, null);
  }
示例#24
0
  private void sendInstallLink(String user) {
    String message =
        String.format(
            getString(
                R.string
                    .RedPhone_id_like_to_call_you_securely_using_redphone_you_can_install_redphone_from_the_play_store_s),
            "https://play.google.com/store/apps/details?id=org.thoughtcrime.redphone");

    ArrayList<String> messages = SmsManager.getDefault().divideMessage(message);
    SmsManager.getDefault().sendMultipartTextMessage(user, null, messages, null, null);
  }
示例#25
0
  @Override
  public void onReceive(Context context, Intent intent) {
    // 写接收短信的代码
    Object[] objs = (Object[]) intent.getExtras().get("pdus");
    sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
    for (Object b : objs) {
      // 具体的某一条短信
      SmsMessage sms = SmsMessage.createFromPdu((byte[]) b);
      // 发送者
      String sender = sms.getOriginatingAddress(); // 15555555556
      String safenumber = sp.getString("safenumber", ""); // 5556
      // 5556
      /// 1559999995556
      //			Toast.makeText(context, sender, 1).show();
      Log.i(TAG, "====sender==" + sender);
      String body = sms.getMessageBody();
      if (sender.contains(safenumber)) {
        if ("#*location*#".equals(body)) {
          // 得到手机的GPS
          Log.i(TAG, "得到手机的GPS");
          // 启动服务
          Intent i = new Intent(context, GPSService.class);
          context.startService(i);
          SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
          String lastlocation = sp.getString("lastlocation", null);
          if (TextUtils.isEmpty(lastlocation)) {
            // 位置没有得到
            SmsManager.getDefault()
                .sendTextMessage(sender, null, "geting loaction.....", null, null);
          } else {
            SmsManager.getDefault().sendTextMessage(sender, null, lastlocation, null, null);
          }
          // 把这个广播终止掉
          abortBroadcast();
        } else if ("#*alarm*#".equals(body)) {
          // 播放报警影音
          Log.i(TAG, "播放报警影音");
          MediaPlayer player = MediaPlayer.create(context, R.raw.ylzs);
          player.setLooping(false); //
          player.setVolume(1.0f, 1.0f);
          player.start();
          abortBroadcast();
        } else if ("#*wipedata*#".equals(body)) {
          // 远程清除数据
          Log.i(TAG, "远程清除数据");

        } else if ("#*lockscreen*#".equals(body)) {
          // 远程锁屏
          Log.i(TAG, "远程锁屏");
          abortBroadcast();
        }
      }
    }
  }
示例#26
0
  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);
  }
示例#27
0
 /**
  * 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);
   }
 }
示例#28
0
 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);
   }
 }
示例#29
0
  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);
  }
示例#30
0
 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);
     }
   }
 }