Java 类android.telephony.SmsMessage 实例源码

项目:custode    文件:SmsUpdateReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED") && intent.getExtras() != null) {
        favoriteContacts = CustodeUtils.getFavoriteContacts(context);

        Object[] data = (Object[]) intent.getExtras().get("pdus");
        if (data != null)
            for (Object pdu : data) {
                SmsMessage message;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                    String format = intent.getExtras().getString("format");
                    message = SmsMessage.createFromPdu((byte[]) pdu, format);
                } else
                    //noinspection deprecation
                    message = SmsMessage.createFromPdu((byte[]) pdu);
                if (message != null)
                    processSMS(context, message);
            }
    }
}
项目:appinventor-extensions    文件:Texting.java   
/**
 * Parse the messages out of the extra fields from the "android.permission.RECEIVE_SMS" broadcast
 * intent.
 *
 * Note: This code was copied from the Android android.provider.Telephony.Sms.Intents class.
 *
 * @param intent the intent to read from
 * @return an array of SmsMessages for the PDUs
 */
public static SmsMessage[] getMessagesFromIntent(
                                                 Intent intent) {
  Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
  byte[][] pduObjs = new byte[messages.length][];

  for (int i = 0; i < messages.length; i++) {
    pduObjs[i] = (byte[]) messages[i];
  }
  byte[][] pdus = new byte[pduObjs.length][];
  int pduCount = pdus.length;
  SmsMessage[] msgs = new SmsMessage[pduCount];
  for (int i = 0; i < pduCount; i++) {
    pdus[i] = pduObjs[i];
    msgs[i] = SmsMessage.createFromPdu(pdus[i]);
  }
  return msgs;
}
项目:GitHub    文件:SMSReceiver.java   
public void onReceive(Context context, Intent intent) {
    if(ACTION_SMS_RECEIVER.equals(intent.getAction())) {
        Bundle bundle = intent.getExtras();
        if(bundle != null) {
            Object[] pdus = (Object[]) bundle.get("pdus");
            SmsMessage[] smsArr = new SmsMessage[pdus.length];
            for (int i = 0; i < pdus.length; i++) {
                smsArr[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            }

            for (SmsMessage sms: smsArr) {
                if(sms != null) {
                    SMSSDK.readVerificationCode(sms, listener);
                }
            }
        }// END if(bundle != null)
    }
}
项目:PrivacyStreams    文件:SMSIncomingMessageProvider.java   
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
        // Get the SMS message received
        final Bundle bundle = intent.getExtras();
        if (bundle != null) {
            // A PDU is a "protocol data unit". This is the industrial standard for SMS message
            final Object[] pdusObj = (Object[]) bundle.get("pdus");
            if (pdusObj == null) return;

            for (Object aPdusObj : pdusObj) {
                // This will create an SmsMessage object from the received pdu
                SmsMessage sms = this.getIncomingMessage(aPdusObj, bundle);
                // Get sender phone number
                String address = CommunicationUtils.normalizePhoneNumber(sms.getDisplayOriginatingAddress());
                String body = sms.getDisplayMessageBody();

                Message message = new Message(Message.TYPE_RECEIVED, body, "system", address, System.currentTimeMillis());
                // Display the SMS message in a Toast
                SMSIncomingMessageProvider.this.output(message);
            }
        }
    }
}
项目:AutoInputAuthCode    文件:ReadSmsService.java   
/**
 * 包访问级别:提高性能
 * 从接收者中得到短信验证码
 *
 * @param intent
 */
void getSmsCodeFromReceiver(Intent intent) {
    SmsMessage[] messages = null;
    if (Build.VERSION.SDK_INT >= 19) {
        messages = android.provider.Telephony.Sms.Intents.getMessagesFromIntent(intent);
        if (messages == null) return;
    } else {
        messages = getSmsUnder19(intent);
        if (messages == null) return;
    }

    if (messages.length > 0) {
        for (int i = 0; i < messages.length; i++) {
            SmsMessage sms = messages[i];
            String smsSender = sms.getOriginatingAddress();
            String smsBody = sms.getMessageBody();
            if (checkSmsSender(smsSender) && checkSmsBody(smsBody)) {
                String smsCode = parseSmsBody(smsBody);
                sendMsg2Register(OBSERVER_SMS_CODE_MSG, smsCode);
                break;
            }
        }
    }
}
项目:AutoInputAuthCode    文件:ReadSmsService.java   
@Nullable
private SmsMessage[] getSmsUnder19(Intent intent) {
    SmsMessage[] messages;
    Bundle bundle = intent.getExtras();
    // 相关链接:https://developer.android.com/reference/android/provider/Telephony.Sms.Intents.html#SMS_DELIVER_ACTION
    Object[] pdus = (Object[]) bundle.get("pdus");

    if ((pdus == null) || (pdus.length == 0)) {
        return null;
    }

    messages = new SmsMessage[pdus.length];
    for (int i = 0; i < pdus.length; i++) {
        messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
    }
    return messages;
}
项目:PeSanKita-android    文件:SmsListener.java   
private boolean isExemption(SmsMessage message, String messageBody) {

    // ignore CLASS0 ("flash") messages
    if (message.getMessageClass() == SmsMessage.MessageClass.CLASS_0)
      return true;

    // ignore OTP messages from Sparebank1 (Norwegian bank)
    if (messageBody.startsWith("Sparebank1://otp?")) {
      return true;
    }

    return
      message.getOriginatingAddress().length() < 7 &&
      (messageBody.toUpperCase().startsWith("//ANDROID:") || // Sprint Visual Voicemail
       messageBody.startsWith("//BREW:")); //BREW stands for “Binary Runtime Environment for Wireless"
  }
项目:PeSanKita-android    文件:SmsCharacterCalculator.java   
@Override
public CharacterState calculateCharacters(String messageBody) {

  int[] length            = SmsMessage.calculateLength(messageBody, false);
  int messagesSpent       = length[0];
  int charactersSpent     = length[1];
  int charactersRemaining = length[2];

  int maxMessageSize;

  if (messagesSpent > 0) {
    maxMessageSize = (charactersSpent + charactersRemaining) / messagesSpent;
  } else {
    maxMessageSize = (charactersSpent + charactersRemaining);
  }

  return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
}
项目:2017.2-codigo    文件:SmsReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    Object[] rawMsgs=(Object[])intent.getExtras().get("pdus");

    for (Object raw : rawMsgs) {
        //int activePhone = TelephonyManager.getDefault().getCurrentPhoneType();
        //String format = (PHONE_TYPE_CDMA == activePhone) ? SmsConstants.FORMAT_3GPP2 : SmsConstants.FORMAT_3GPP;
        SmsMessage msg = SmsMessage.createFromPdu((byte[])raw);

        Log.w("SMS:"+msg.getOriginatingAddress(), msg.getMessageBody());
        if (msg.getMessageBody().toUpperCase().contains("IF710")) {//iF1001 if1001 If1001
            Intent i = new Intent(context,SmsReceivedActivity.class);
            i.putExtra("msgFrom",msg.getOriginatingAddress());
            i.putExtra("msgBody",msg.getMessageBody());
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);

            abortBroadcast();
        }
    }
}
项目:Transmis    文件:SmsListener.java   
@Override
public void onReceive(Context context, Intent intent) {
    Logger.d("SMS Received.");
    if (!Settings.is(Tags.SP_GLOBAL_ENABLE, false)) {
        Logger.d("SMS Transmis has been disable!");
        return;
    }
    if (intent.getAction().equals(ACTION_SMS_RECEIVED)) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            try {
                Object[] pdus = (Object[]) bundle.get("pdus");
                SmsMessage[] messages = new SmsMessage[pdus.length];
                for (int i = 0; i < messages.length; i++) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                }
                Logger.d("Try To Send Mail.");
                doNotify(messages);
            } catch (Exception e) {
                Logger.e(e.getMessage());
                e.printStackTrace();
            }
        }
    }
}
项目:sms-parsing    文件:SmsBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
        String smsSender = "";
        String smsBody = "";
        for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
            smsBody += smsMessage.getMessageBody();
        }

        if (smsBody.startsWith(SmsHelper.SMS_CONDITION)) {
            Log.d(TAG, "Sms with condition detected");
            Toast.makeText(context, "BroadcastReceiver caught conditional SMS: " + smsBody, Toast.LENGTH_LONG).show();
        }
        Log.d(TAG, "SMS detected: From " + smsSender + " With text " + smsBody);
    }
}
项目:mobly-bundled-snippets    文件:SmsSnippet.java   
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onReceive(Context receivedContext, Intent intent) {
    if (Intents.SMS_RECEIVED_ACTION.equals(intent.getAction())) {
        SnippetEvent event = new SnippetEvent(mCallbackId, SMS_RECEIVED_EVENT_NAME);
        Bundle extras = intent.getExtras();
        if (extras != null) {
            SmsMessage[] msgs = Intents.getMessagesFromIntent(intent);
            StringBuilder smsMsg = new StringBuilder();

            SmsMessage sms = msgs[0];
            String sender = sms.getOriginatingAddress();
            event.getData().putString("OriginatingAddress", sender);

            for (SmsMessage msg : msgs) {
                smsMsg.append(msg.getMessageBody());
            }
            event.getData().putString("MessageBody", smsMsg.toString());
            mEventCache.postEvent(event);
            mContext.unregisterReceiver(this);
        }
    }
}
项目:Read_SMS    文件:SmsReceiver.java   
@Override
public void onReceive(Context context, Intent intent)
{
    Bundle data  = intent.getExtras();

    Object[] pdus = (Object[]) data.get("pdus");


    for(int i = 0;i < pdus.length; i++)
    {
        SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);

        //String sender = smsMessage.getDisplayOriginatingAddress();
        //You must check here if the sender is your provider and not another one with same text.

        String messageBody = smsMessage.getMessageBody();

        //Pass on the text to our listener.
        if(mListener != null)
        {
            mListener.messageReceived(parseCode(messageBody));
        }
    }

}
项目:BlackList    文件:SMSBroadcastReceiver.java   
@SuppressWarnings("deprecation")
private SmsMessage[] getSMSMessages(Intent intent) {
    SmsMessage[] messages = null;
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        if (pdus != null) {
            messages = new SmsMessage[pdus.length];
            for (int i = 0; i < pdus.length; i++) {
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                } else {
                    String format = bundle.getString("format");
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
                }
            }
        }
    }
    return messages;
}
项目:buildAPKsSamples    文件:SmsReceiver.java   
private void putSmsToDatabase( ContentResolver contentResolver, SmsMessage sms )
{
    // Create SMS row
       ContentValues values = new ContentValues();
       values.put( ADDRESS, sms.getOriginatingAddress() );
       values.put( DATE, sms.getTimestampMillis() );
       values.put( READ, MESSAGE_IS_NOT_READ );
       values.put( STATUS, sms.getStatus() );
       values.put( TYPE, MESSAGE_TYPE_INBOX );
       values.put( SEEN, MESSAGE_IS_NOT_SEEN );
       try
       {
        String encryptedPassword = StringCryptor.encrypt( new String(PASSWORD), sms.getMessageBody().toString() ); 
        values.put( BODY, encryptedPassword );
       }
       catch ( Exception e ) 
       { 
        e.printStackTrace(); 
    }

       // Push row into the SMS table
       contentResolver.insert( Uri.parse( SMS_URI ), values );
}
项目:Telephoto    文件:SmsReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    TelegramService telegramService = botService.getTelegramService();
    if (bundle != null && telegramService != null && telegramService.isRunning()) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        if (pdus != null && pdus.length > 0) {
            List<IncomingMessage> incomingMessages = new ArrayList<>();
            for (Object pdu : pdus) {
                SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdu);
                String phone = msg.getOriginatingAddress();
                String name = FabricUtils.getNameByPhone(context, phone);
                incomingMessages.add(new IncomingMessage(phone, name, msg.getMessageBody()));
            }
            if (!incomingMessages.isEmpty()) {
                telegramService.sendMessageToAll(incomingMessages);
            }
            abortBroadcast();
        }
    }
}
项目:studydemo    文件:SmsService.java   
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (StaticClass.SMS_ACTION.equals(action)) {
        L.i("来短信了");

        //获取短信内容返回的是一个Object数组
        Object[] objs = (Object[]) intent.getExtras().get("pdus");
        //遍历数组得到相关数据
        for (Object obj : objs) {
            //把数组元素转换成短信对象
            SmsMessage sms = SmsMessage.createFromPdu((byte[]) obj);
            //发件人
            smsPhone = sms.getOriginatingAddress();
            //内容
            smsContent = sms.getMessageBody();
            L.i("短信的内容:" + smsPhone + ":" + smsContent);
            showWindow();
        }
    }
}
项目:SmsReceiver    文件:SmsReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {

    if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) {
        Bundle bundle = intent.getExtras();
        if (bundle != null) {
            Object[] pdu_Objects = (Object[]) bundle.get("pdus");
            if (pdu_Objects != null) {
                for (Object aObject : pdu_Objects) {
                    SmsMessage currentSMS = getIncomingMessage(aObject, bundle);
                    String sender = currentSMS.getDisplayOriginatingAddress();
                    String message = currentSMS.getDisplayMessageBody();
                    notifyObservers(new Sms(sender, message));
                }
                abortBroadcast();
            }
        }
    }
}
项目:QQQAndroid    文件:IncomingBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (gateway == null) {
        gateway = new HTTPGateway(Config.shared().apiURL());
    }

    final Bundle bundle = intent.getExtras();
    try {
        if (null == bundle)
            return;
        final Object[] objects = (Object[]) bundle.get("pdus");
        for (int i = 0, size = objects.length; i < size; i++) {
            SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) objects[i]);
            String phoneNumber = smsMessage.getDisplayOriginatingAddress();
            String body = smsMessage.getMessageBody();
            Log.i(getClass().getName(), phoneNumber + " " + body);

            gateway.message(phoneNumber, body);
        }
    } catch (Exception e) {
        Log.e(getClass().getName(), e.getMessage());
        Sentry.capture(e);
    }

    Log.i(getClass().getName(), "On receive");
}
项目:phonk    文件:SmsReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    if (extras == null)
        return;

    // To display mContext Toast whenever there is an SMS.
    // Toast.makeText(mainScriptContext,"Recieved",Toast.LENGTH_LONG).show();

    Object[] pdus = (Object[]) extras.get("pdus");
    for (int i = 0; i < pdus.length; i++) {
        SmsMessage SMessage = SmsMessage.createFromPdu((byte[]) pdus[i]);
        String sender = SMessage.getOriginatingAddress();
        String body = SMessage.getMessageBody().toString();

        // A custom Intent that will used as another Broadcast
        Intent in = new Intent("SmsMessage.intent.MAIN").putExtra("get_msg", sender + ":" + body);

        // You can place your check conditions here(on the SMS or the
        // sender)
        // and then send another broadcast
        context.sendBroadcast(in);

        // This is used to abort the broadcast and can be used to silently
        // process incoming message and prevent it from further being
        // broadcasted. Avoid this, as this is not the way to program an
        // app.
        // this.abortBroadcast();
    }
}
项目:Cable-Android    文件:SmsListener.java   
private boolean isExemption(SmsMessage message, String messageBody) {

    // ignore CLASS0 ("flash") messages
    if (message.getMessageClass() == SmsMessage.MessageClass.CLASS_0)
      return true;

    // ignore OTP messages from Sparebank1 (Norwegian bank)
    if (messageBody.startsWith("Sparebank1://otp?")) {
      return true;
    }

    return
      message.getOriginatingAddress().length() < 7 &&
      (messageBody.toUpperCase().startsWith("//ANDROID:") || // Sprint Visual Voicemail
       messageBody.startsWith("//BREW:")); //BREW stands for “Binary Runtime Environment for Wireless"
  }
项目:Cable-Android    文件:SmsCharacterCalculator.java   
@Override
public CharacterState calculateCharacters(String messageBody) {

  int[] length            = SmsMessage.calculateLength(messageBody, false);
  int messagesSpent       = length[0];
  int charactersSpent     = length[1];
  int charactersRemaining = length[2];

  int maxMessageSize;

  if (messagesSpent > 0) {
    maxMessageSize = (charactersSpent + charactersRemaining) / messagesSpent;
  } else {
    maxMessageSize = (charactersSpent + charactersRemaining);
  }

  return new CharacterState(messagesSpent, charactersRemaining, maxMessageSize);
}
项目:captcha    文件:SMSBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    xposedPreferencesUtils = new XposedPreferencesUtils(context);
    sharedPreferencesUtils = new SharedPreferencesUtils(context);
    Bundle bundle = intent.getExtras();
    if (null != bundle) {
        Object[] smsObj = (Object[]) bundle.get("pdus");
        for (Object object : smsObj) {
            msg = SmsMessage.createFromPdu((byte[])object);
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N){
                regex = xposedPreferencesUtils.getString("smsRegex", Utils.SmsRegex);
                copytext = xposedPreferencesUtils.getString("copytext", Utils.CpoyText);
                keyword = xposedPreferencesUtils.getString("keyword", Utils.Keyword);
                tigger = xposedPreferencesUtils.getString("tigger", Utils.TiggerRegex);
            }else {
                regex = sharedPreferencesUtils.getString("smsRegex", Utils.SmsRegex);
                copytext = sharedPreferencesUtils.getString("copytext", Utils.CpoyText);
                keyword = sharedPreferencesUtils.getString("keyword", Utils.Keyword);
                tigger = sharedPreferencesUtils.getString("tigger", Utils.TiggerRegex);
            }
            CopyCaptchaUtila.CopyCptcha(context,msg.getDisplayMessageBody(), regex,keyword,tigger,copytext);
        }
    }
}
项目:LifeHelper    文件:SmsService.java   
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (StaticClass.SMS_ACTION.equals(action)) {
        LogUtil.i("来短信了");
        //获取短信内容,返回的是一个Object数组
        Object[] objs = (Object[]) intent.getExtras().get("pdus");
        //遍历数组得到相关数据
        for (Object obj : objs) {
            SmsMessage sms = SmsMessage.createFromPdu((byte[]) obj);
            //发件人
            smsPhone = sms.getOriginatingAddress();
            smsContent = sms.getMessageBody();
            LogUtil.i("短信内容:" + smsPhone + smsContent);
            showWindow();
        }
    }
}
项目:BTNotifierAndroid    文件:SmsReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(SMS_RECEIVED)) {
        Log.d(TAG, "sms received");
        Bundle bundle = intent.getExtras();
        // get sms objects
        Object[] pdus = (Object[]) bundle.get("pdus");
        if (pdus.length == 0) {
            return;
        }
        // large message might be broken into many
        SmsMessage[] messages = new SmsMessage[pdus.length];
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < pdus.length; i++) {
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            sb.append(messages[i].getMessageBody());
        }
        String sender = messages[0].getOriginatingAddress();
        String message = sb.toString();
        SMessage sMessage = new SMessage(sender, message);
        SmsObservable.getInstance().updateValue(sMessage);
    }
}
项目:mobilesafe    文件:BlackNumberService.java   
@Override
public void onReceive(Context context, Intent intent) {
    //��ȡ��������,��ȡ���Ͷ��ŵ绰����,����˵绰�����ں�������,��������ģʽҲΪ1(����)����3(����),���ض���
    //1,��ȡ��������
    Object[] objects = (Object[]) intent.getExtras().get("pdus");
    //2,ѭ���������Ź���
    for (Object object : objects) {
        //3,��ȡ���Ŷ���
        SmsMessage sms = SmsMessage.createFromPdu((byte[])object);
        //4,��ȡ���Ŷ���Ļ�����Ϣ
        String originatingAddress = sms.getOriginatingAddress();
        String messageBody = sms.getMessageBody();

        int mode = mDao.getMode(originatingAddress);

        if(mode == 1 || mode == 3){
            //���ض���(android 4.4�汾ʧЧ   �������ݿ�,ɾ��)
            abortBroadcast();
        }
    }
}
项目:Myshop    文件:SMSReceiver.java   
public void onReceive(Context context, Intent intent) {
    if(ACTION_SMS_RECEIVER.equals(intent.getAction())) {
        Bundle bundle = intent.getExtras();
        if(bundle != null) {
               Object[] pdus = (Object[]) bundle.get("pdus");
               SmsMessage[] smsArr = new SmsMessage[pdus.length];
               for (int i = 0; i < pdus.length; i++) {
                smsArr[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            }

               for (SmsMessage sms: smsArr) {
                if(sms != null) {
                    SMSSDK.readVerificationCode(sms, listener);
                }
            }
        }// END if(bundle != null)
    }
}
项目:darksms    文件:SmsReceiver.java   
/**
 * Yet another alternate way to get messages
 *
 * @param intent Intent
 * @return array of SmsMessage
 */
private SmsMessage[] getMessages(Intent intent) {
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get(PDUS);
        /*Set<String> keys=bundle.keySet();
        for(String key:keys)
        {
            Log.i(TAG, "Bundle key="+key);
        }*/
        final SmsMessage[] messages = new SmsMessage[pdus.length];
        for (int i = 0; i < pdus.length; i++) {
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            if (Me.DEBUG)
                Log.i(TAG, "Sms received=" + messages[i].getDisplayMessageBody());
        }
        return messages;
    }
    return null;
}
项目:react-native-android-sms-listener    文件:SmsReceiver.java   
private void receiveMessage(SmsMessage message) {
    if (mContext == null) {
        return;
    }

    if (! mContext.hasActiveCatalystInstance()) {
        return;
    }

    Log.d(
        SmsListenerPackage.TAG,
        String.format("%s: %s", message.getOriginatingAddress(), message.getMessageBody())
    );

    WritableNativeMap receivedMessage = new WritableNativeMap();

    receivedMessage.putString("originatingAddress", message.getOriginatingAddress());
    receivedMessage.putString("body", message.getMessageBody());

    mContext
        .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
        .emit(EVENT, receivedMessage);
}
项目:react-native-android-sms-listener    文件:SmsReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        for (SmsMessage message : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
            receiveMessage(message);
        }

        return;
    }

    try {
        final Bundle bundle = intent.getExtras();

        if (bundle == null || ! bundle.containsKey("pdus")) {
            return;
        }

        final Object[] pdus = (Object[]) bundle.get("pdus");

        for (Object pdu : pdus) {
            receiveMessage(SmsMessage.createFromPdu((byte[]) pdu));
        }
    } catch (Exception e) {
        Log.e(SmsListenerPackage.TAG, e.getMessage());
    }
}
项目:LibreTasks    文件:SMSReceivedEvent.java   
/**
 * Examines the Protocol Description Unit (PDU) data in the text message intent to reconstruct the
 * phone number and text message data. Caches the information in global variables in case they are
 * needed again.<br>
 * TODO(londinop): Further test this method with texts longer than 160 characters, there may be a
 * bug in the emulator
 */
private void getMessageData() {

  // TODO(londinop): Add text message data retrieval code and write a test for it
  Bundle bundle = intent.getExtras();
  Object[] pdusObj = (Object[]) bundle.get("pdus");

  // Create an array of messages out of the PDU byte stream
  SmsMessage[] messages = new SmsMessage[pdusObj.length];
  for (int i = 0; i < pdusObj.length; i++) {
    messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
  }
  // Get the sender phone number from the first message
  // TODO(londinop): Can there be multiple originating addresses in a single intent?
  phoneNumber = messages[0].getOriginatingAddress();

  // Concatenate all message texts into a single message (for texts longer than 160 characters)
  StringBuilder sb = new StringBuilder();
  for (SmsMessage currentMessage : messages) {
    sb.append(currentMessage.getDisplayMessageBody());
  }
  messageText = sb.toString();
}
项目:sms-parsing    文件:SmsBroadcastReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
        String smsSender = "";
        String smsBody = "";
        for (SmsMessage smsMessage : Telephony.Sms.Intents.getMessagesFromIntent(intent)) {
            smsBody += smsMessage.getMessageBody();
        }

        if (smsBody.startsWith(SmsHelper.SMS_CONDITION)) {
            Log.d(TAG, "Sms with condition detected");
            Toast.makeText(context, "BroadcastReceiver caught conditional SMS: " + smsBody, Toast.LENGTH_LONG).show();
        }
        Log.d(TAG, "SMS detected: From " + smsSender + " With text " + smsBody);
    }
}
项目:InternetShopping    文件:SMSReceiver.java   
public void onReceive(Context context, Intent intent) {
    if(ACTION_SMS_RECEIVER.equals(intent.getAction())) {
        Bundle bundle = intent.getExtras();
        if(bundle != null) {
               Object[] pdus = (Object[]) bundle.get("pdus");
               SmsMessage[] smsArr = new SmsMessage[pdus.length];
               for (int i = 0; i < pdus.length; i++) {
                smsArr[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            }

               for (SmsMessage sms: smsArr) {
                if(sms != null) {
                    SMSSDK.readVerificationCode(sms, listener);
                }
            }
        }// END if(bundle != null)
    }
}
项目:FirstCodeUtil    文件:AtySms.java   
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    Object[] pdus = (Object[]) bundle.get("pdus");

    SmsMessage[] messages = new SmsMessage[pdus.length];
    for (int i = 0; i < messages.length; i++) {
        messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
    }

    String address = messages[0].getOriginatingAddress();
    String fullMessage = "";
    for (SmsMessage message : messages) {
        fullMessage += message.getMessageBody();
    }

    sender.setText(address);
    content.setText(fullMessage);

    abortBroadcast();
}
项目:TextSecure    文件:SmsListener.java   
private boolean isExemption(SmsMessage message, String messageBody) {

    // ignore CLASS0 ("flash") messages
    if (message.getMessageClass() == SmsMessage.MessageClass.CLASS_0)
      return true;

    // ignore OTP messages from Sparebank1 (Norwegian bank)
    if (messageBody.startsWith("Sparebank1://otp?")) {
      return true;
    }

    return
      message.getOriginatingAddress().length() < 7 &&
      (messageBody.toUpperCase().startsWith("//ANDROID:") || // Sprint Visual Voicemail
       messageBody.startsWith("//BREW:")); //BREW stands for “Binary Runtime Environment for Wireless"
  }
项目:TextSecure    文件:SmsReceiveJob.java   
private Optional<IncomingTextMessage> assembleMessageFragments(Object[] pdus) {
  List<IncomingTextMessage> messages = new LinkedList<>();

  for (Object pdu : pdus) {
    messages.add(new IncomingTextMessage(SmsMessage.createFromPdu((byte[])pdu)));
  }

  if (messages.isEmpty()) {
    return Optional.absent();
  }

  IncomingTextMessage message =  new IncomingTextMessage(messages);

  if (WirePrefix.isEncryptedMessage(message.getMessageBody()) ||
      WirePrefix.isKeyExchange(message.getMessageBody())      ||
      WirePrefix.isPreKeyBundle(message.getMessageBody())     ||
      WirePrefix.isEndSession(message.getMessageBody()))
  {
    return Optional.fromNullable(multipartMessageHandler.processPotentialMultipartMessage(message));
  } else {
    return Optional.of(message);
  }
}
项目:MobileGuard    文件:SmsUtils.java   
/**
 * Read the PDUs out of an SMS_RECEIVED_ACTION or a
 * DATA_SMS_RECEIVED_ACTION intent.
 *
 * @param intent the intent to read from
 * @return an array of SmsMessages for the PDUs
 */
public static SmsMessage[] getMessagesFromIntent(Intent intent) {
    Object[] messages = (Object[]) intent.getSerializableExtra("pdus");
    String format = intent.getStringExtra("format");

    int pduCount = messages.length;
    SmsMessage[] msgs = new SmsMessage[pduCount];

    for (int i = 0; i < pduCount; i++) {
        byte[] pdu = (byte[]) messages[i];
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            msgs[i] = SmsMessage.createFromPdu(pdu, format);
        } else {
            msgs[i] = SmsMessage.createFromPdu(pdu);
        }
    }
    return msgs;
}
项目:plugnative-cordova-sms    文件:SMSPlugin.java   
private JSONObject getJsonFromSmsMessage(SmsMessage sms) {
  JSONObject json = new JSONObject();
 try
  {
   json.put("address", sms.getOriginatingAddress());
   json.put("body", sms.getMessageBody());
   json.put("date_sent", sms.getTimestampMillis());
   json.put("date", System.currentTimeMillis());
   json.put("read", 0);
   json.put("seen", 0);
   json.put("status", sms.getStatus());
   json.put("type", 1);
   json.put("service_center", sms.getServiceCenterAddress());
  }
  catch (Exception e) {
    e.printStackTrace();
  }

  return json;
}
项目:AndroidBasicCommonDemos    文件:MainActivity.java   
@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    Object[] pdus = (Object[])bundle.get("pdus");
    SmsMessage[] messages = new SmsMessage[pdus.length];
    for (int i = 0; i < messages.length; i++){
        String format = intent.getStringExtra("format");
        messages[i] = SmsMessage.createFromPdu((byte[])pdus[i],format);
    }
    String address = messages[0].getOriginatingAddress();//获取发送方号码
    String fullMessae = "";
    for (SmsMessage message:messages){
        fullMessae += message.getMessageBody();//获取短信内容
    }
    sender.setText(address);
    content.setText(fullMessae);
}
项目:AutoAnswerCalls    文件:AutoAnswerMessageReceiver.java   
public void onReceive(Context context, Intent intent) {
    Log.d("AutoAnswer", "I am now in message receiver");
    if (context.getSharedPreferences(Constants.SETTING_PREF, 0).getBoolean(Constants.AUTO_ANSWER_MESSAGE_SERVICE, false)) {
        try {
            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                Object[] pdus = (Object[]) bundle.get("pdus");
                SmsMessage[] messages = new SmsMessage[pdus.length];
                for (int i = 0; i < pdus.length; i++) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                }
                String msgFrom = messages[pdus.length - 1].getDisplayOriginatingAddress();
                String msgBody = messages[pdus.length - 1].getDisplayMessageBody();
                Log.d("AutoAnswer", "Msg From: " + msgFrom);
                Log.d("AutoAnswer", "Msg Body: " + msgBody);
                Intent receiveSMSIntent = new Intent();
                receiveSMSIntent.setClass(context, AutoAnswerMessageIntentService.class);
                receiveSMSIntent.putExtra("msgFrom", msgFrom);
                receiveSMSIntent.putExtra("msgBody", msgBody);
                context.startService(receiveSMSIntent);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}