示例#1
0
 @Override
 public void onReceive(Context context, Intent intent) {
   try {
     Log.d(G.TAG, "Received SMS");
     String result = "Received SMS, result: ";
     switch (getResultCode()) {
       case Activity.RESULT_OK:
         result += "Message Received!";
         break;
       default:
         result += "Error when receiving Message";
         break;
     }
     Log.d(G.TAG, result);
     Utils.showResultInDialog(mActivity, result);
   } catch (Exception e) {
     e.printStackTrace();
     Log.e(G.TAG, e.getMessage());
     Utils.showResultInDialog(mActivity, "Error when receiving Message: " + e.getMessage());
   }
 }
示例#2
0
  private void sendDataSms(String phoneNumber, String message) {

    short SMS_PORT = 8901;
    SmsManager smsManager = SmsManager.getDefault();
    if (smsManager == null) {
      Utils.showResultInDialog(mActivity, G.NOTHING_FOUND + "\n\n smsManager == null");
      return;
    }
    PendingIntent sent =
        mActivity.createPendingResult(
            DATA_SMS_SENT, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
    smsManager.sendDataMessage(phoneNumber, null, SMS_PORT, message.getBytes(), sent, null);
  }
示例#3
0
  private boolean refreshAndVerifiyTarget(int mode) {
    String target;
    switch (mode) {
      case SEND_MODE_SMS:
        if (!refreshAndVerifiyText()) {
          return false;
        }
        if (ed_numbertosend == null) {
          return false;
        }
        target = ed_numbertosend.getText().toString();
        if (TextUtils.isEmpty(target)) {
          Toast.makeText(mActivity, mActivity.getString(R.string.enternumber), Toast.LENGTH_SHORT)
              .show();
          return false;
        }
        if (!TextUtils.isDigitsOnly(target)) {
          Toast.makeText(mActivity, mActivity.getString(R.string.numbersonly), Toast.LENGTH_SHORT)
              .show();
          return false;
        }

        numberToSend = target;
        return true;

      case SEND_MODE_DATASMS:
        if (!refreshAndVerifiyText()) {
          return false;
        }
        if (ed_numbertosend == null) {
          return false;
        }
        target = ed_numbertosend.getText().toString();
        if (TextUtils.isEmpty(target)) {
          Toast.makeText(mActivity, mActivity.getString(R.string.enternumber), Toast.LENGTH_SHORT)
              .show();
          return false;
        }
        if (!TextUtils.isDigitsOnly(target)) {
          Toast.makeText(mActivity, mActivity.getString(R.string.numbersonly), Toast.LENGTH_SHORT)
              .show();
          return false;
        }

        numberToSend = target;
        return true;

      case SEND_MODE_EMAIL:
        if (!refreshAndVerifiyText()) {
          return false;
        }
        if (ed_mailtosend == null) {
          return false;
        }
        target = ed_mailtosend.getText().toString();
        if (TextUtils.isEmpty(target) || !Utils.isTextEmailAddress(target)) {
          Toast.makeText(
                  mActivity, mActivity.getString(R.string.enteremailaddress), Toast.LENGTH_SHORT)
              .show();
          return false;
        }

        mailToSend = target;
        return true;

      default:
        break;
    }

    return false;
  }