コード例 #1
0
        @Override
        public void onReceive(Context context, Intent intent) {
          switch (getResultCode()) {
            case Activity.RESULT_OK:
              mCryptoCallService.sendUpdateUiToHandler(R.string.status_sms_delivered);
              break;
            case Activity.RESULT_CANCELED:
              mCryptoCallService.sendUpdateUiToHandler(R.string.status_sms_not_delivered);
              break;
          }

          unregisterReceivers(context);
        }
コード例 #2
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);
    }
  }
コード例 #3
0
 @Override
 public void onReceive(Context context, Intent intent) {
   switch (getResultCode()) {
     case Activity.RESULT_OK:
       mCryptoCallService.sendUpdateUiToHandler(R.string.status_sms_sent, 100);
       break;
     case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
       mCryptoCallService.sendUpdateUiToHandler(R.string.status_sms_generic);
       break;
     case SmsManager.RESULT_ERROR_NO_SERVICE:
       mCryptoCallService.sendUpdateUiToHandler(R.string.status_sms_no_service);
       break;
     case SmsManager.RESULT_ERROR_NULL_PDU:
       mCryptoCallService.sendUpdateUiToHandler(R.string.status_sms_null_pdu);
       break;
     case SmsManager.RESULT_ERROR_RADIO_OFF:
       mCryptoCallService.sendUpdateUiToHandler(R.string.status_sms_radio_off);
       break;
   }
 }