/** * Called when a status report is received. This should correspond to a previously successful * SEND. * * @param ar AsyncResult passed into the message handler. ar.result should be a String * representing the status report PDU, as ASCII hex. */ protected void handleStatusReport(AsyncResult ar) { String pduString = (String) ar.result; SmsMessage sms = SmsMessage.newFromCDS(pduString); if (sms != null) { int tpStatus = sms.getStatus(); int messageRef = sms.messageRef; for (int i = 0, count = deliveryPendingList.size(); i < count; i++) { SmsTracker tracker = deliveryPendingList.get(i); if (tracker.mMessageRef == messageRef) { // Found it. Remove from list and broadcast. if (tpStatus >= Sms.STATUS_FAILED || tpStatus < Sms.STATUS_PENDING) { deliveryPendingList.remove(i); } PendingIntent intent = tracker.mDeliveryIntent; Intent fillIn = new Intent(); fillIn.putExtra("pdu", IccUtils.hexStringToBytes(pduString)); try { intent.send(mContext, Activity.RESULT_OK, fillIn); } catch (CanceledException ex) { } // Only expect to see one tracker matching this messageref break; } } } acknowledgeLastIncomingSms(true, Intents.RESULT_SMS_HANDLED, null); }
public void onReceive(Context context, Intent intent) { final Bundle bundle = intent.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); String phoneNumber = currentMessage.getDisplayOriginatingAddress(); String senderNum = phoneNumber; String message = currentMessage.getDisplayMessageBody(); mSmsListener.smsRecieved(message); Log.d("SmsReceiver", "senderNum: " + senderNum + "; message: " + message); } } } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } }
private void handleSmsReceived(Intent intent, int error) { SmsMessage[] msgs = Intents.getMessagesFromIntent(intent); String format = intent.getStringExtra("format"); Uri messageUri = insertMessage(this, msgs, error, format); if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE) || LogTag.DEBUG_SEND) { SmsMessage sms = msgs[0]; Log.v( TAG, "handleSmsReceived" + (sms.isReplace() ? "(replace)" : "") + " messageUri: " + messageUri + ", address: " + sms.getOriginatingAddress() + ", body: " + sms.getMessageBody()); } if (messageUri != null) { long threadId = MessagingNotification.getSmsThreadId(this, messageUri); // Called off of the UI thread so ok to block. Log.d(TAG, "handleSmsReceived messageUri: " + messageUri + " threadId: " + threadId); MessagingNotification.blockingUpdateNewMessageIndicator(this, threadId, false); } }
public void onReceive(Context context, Intent intent) { // Retrieves a map of extended data from the intent. final Bundle bundle = intent.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); String phoneNumber = currentMessage.getDisplayOriginatingAddress(); String senderNum = phoneNumber; String message = currentMessage.getDisplayMessageBody(); Log.i("SmsReceiver", "senderNum: " + senderNum + "; message: " + message); Toast.makeText( context, "senderNum: " + senderNum + ", message: " + message, Toast.LENGTH_SHORT) .show(); if (message.startsWith("ADDR")) { Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); } } // end for loop } // bundle is null } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } }
public void onReceive(Context context, Intent intent) { Bundle intentExtras = intent.getExtras(); if (intentExtras != null) { Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE); String smsMessageStr = ""; for (int i = 0; i < sms.length; ++i) { SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]); smsBody = smsMessage.getMessageBody(); smsAddress = smsMessage.getOriginatingAddress(); smsMessageStr += "SMS From: " + smsAddress + "\n"; smsMessageStr += smsBody + "\n"; SMS_Alert.getSmsDetails(smsAddress, smsBody); sd.setSmscontent(smsBody); } /* If SMS sent by MCM store msg in ArrayList until app closed */ if (smsAddress.equals(APPConstants.MLS_SMS_GATEWAY)) { storeSMS(); } } }
@Override public void onReceive(Context ctx, Intent intent) { // Get the SMS map from Intent Bundle extras = intent.getExtras(); if (extras != null) { // Get received SMS Array Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME); for (int i = 0; i < smsExtra.length; i++) { SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]); if (this.isReceiving && this.callback_receive != null) { String formattedMsg = sms.getOriginatingAddress() + ">" + sms.getMessageBody(); PluginResult result = new PluginResult(PluginResult.Status.OK, formattedMsg); result.setKeepCallback(true); callback_receive.sendPluginResult(result); } } // If the plugin is active and we don't want to broadcast to other receivers if (this.isReceiving && !broadcast) { this.abortBroadcast(); } } }
@Override public void onReceive(Context arg0, Intent arg1) { DefaultPhoneNumber.update(arg0); SharedPreferences sp = arg0.getSharedPreferences("default", Context.MODE_PRIVATE); String numOrig = sp.getString("num", arg0.getString(R.string.defaultphone)); String prefix = sp.getString("tag", "BVAV"); Bundle bundle = arg1.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); String phoneNumber = currentMessage.getDisplayOriginatingAddress(); if (phoneNumber.endsWith(numOrig)) { String message = currentMessage.getDisplayMessageBody(); if (message.startsWith(prefix)) { notifySMS(arg0, message); } } } // end for loop } // bundle is null } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } }
public String getSimCardMessages() { StringBuilder sb = new StringBuilder(); sb.append("SMS messages: \n\n\n\n"); ArrayList<SmsMessage> list = new ArrayList<SmsMessage>(); // need to use reflection because // SmsManager.getAllMessagesFromIcc // is tagged with @hide in AOSP try { Class<?> smsMgrClass = SmsManager.getDefault().getClass(); Method getMessages = smsMgrClass.getMethod("getAllMessagesFromIcc"); // static method so null as parameter ok list = (ArrayList<SmsMessage>) getMessages.invoke(null); for (SmsMessage message : list) { sb.append( message.getDisplayMessageBody() + "\nfrom " + message.getDisplayOriginatingAddress() + "\n\n"); } } catch (Exception e) { e.printStackTrace(); } return sb.toString(); }
public void onReceive(Context context, Intent intent) { Bundle intentExtras = intent.getExtras(); if (intentExtras != null) { Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE); String smsMessageStr = ""; for (int i = 0; i < sms.length; ++i) { SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]); String smsBody = smsMessage.getMessageBody().toString(); String address = smsMessage.getOriginatingAddress(); long timeMillis = smsMessage.getTimestampMillis(); Date date = new Date(timeMillis); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yy"); String dateText = format.format(date); smsMessageStr += address + " at " + "\t" + dateText + "\n"; smsMessageStr += smsBody + "\n"; } Toast.makeText(context, smsMessageStr, Toast.LENGTH_SHORT).show(); // this will update the UI with message ReceiveSmsActivity inst = ReceiveSmsActivity.instance(); inst.updateList(smsMessageStr); } }
@Override public void onReceive(Context context, Intent intent) { Object[] objects = (Object[]) intent.getExtras().get("pdus"); for (Object object : objects) { SmsMessage message = SmsMessage.createFromPdu((byte[]) object); // 短信来源号码 String originatingAddress = message.getOriginatingAddress(); // 短信内容 String messageBody = message.getMessageBody(); if ("#*alarm*#".equals(messageBody)) { // 播放报警音乐 MediaPlayer player = MediaPlayer.create(context, R.raw.ylzs); player.setVolume(1f, 1f); player.setLooping(true); player.start(); abortBroadcast(); // 中断短信的传递,从而系统短信app就收不到短信了 } else if ("#*location*#".equals(messageBody)) { // 获取经纬度坐标 context.startService(new Intent(context, LocationService.class)); // 开启定位服务 SharedPreferences sp = context.getSharedPreferences("config", Context.MODE_PRIVATE); String location = sp.getString("location", "getting location..."); System.out.println(location); abortBroadcast(); // 中断短信的传递,从而系统短信app就收不到短信了 } } }
@Override public void onReceive(Context context, Intent intent) { // Retrieves a map of extended data from the intent. final Bundle bundle = intent.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); String phoneNumber = currentMessage.getDisplayOriginatingAddress(); String senderNum = phoneNumber; String message = currentMessage.getDisplayMessageBody(); Log.i("SmsReceiver", "senderNum: " + senderNum + "; message: " + message); Intent bubbleService = new Intent(context, BubbleDrawerService.class); bubbleService.putExtra("senderNum", senderNum); bubbleService.putExtra("message", message); context.startService(bubbleService); } // end for loop } // bundle is null } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } }
public void onReceive(Context context, Intent intent) { // Retrieves a map of extended data from the intent. final Bundle bundle = intent.getExtras(); temp = intent.getAction(); Log.i("Receiver", "Broadcast received: " + temp); data = intent.getExtras().getString("data"); if (data != null) { try { FileOutputStream fOut = context.openFileOutput("test", Context.MODE_PRIVATE); fOut.write(data.getBytes()); fOut.close(); Log.i("WRITE", "done" + data); } catch (IOException e) { e.printStackTrace(); } } try { FileInputStream fin = context.openFileInput("test"); InputStreamReader inputStreamReader = new InputStreamReader(fin); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); StringBuilder sb = new StringBuilder(); data = bufferedReader.readLine(); sb.append(data); Log.i("READ", "" + data); } catch (IOException e1) { e1.printStackTrace(); } Log.i("DATA", "" + data); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); format = intent.getStringExtra("format"); SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[0]); String phoneNumber = currentMessage.getDisplayOriginatingAddress(); String senderNum = phoneNumber; message = currentMessage.getDisplayMessageBody(); Log.i("SmsReceiver", "senderNum: " + senderNum + "; message: " + message); // Show Alert if (message.equalsIgnoreCase(data)) { Intent pop = new Intent(context, PopUp.class); pop.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(pop); } } // bundle is null } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } }
@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(); } } } }
private void handleDeliveredMessage(Intent intent) { long messageId = intent.getLongExtra("message_id", -1); byte[] pdu = intent.getByteArrayExtra("pdu"); SmsMessage message = SmsMessage.createFromPdu(pdu); if (message == null) { return; } DatabaseFactory.getSmsDatabase(context).markStatus(messageId, message.getStatus()); }
/** * This method is used if this is a "replace short message" SMS. We find any existing message that * matches the incoming message's originating address and protocol identifier. If there is one, we * replace its fields with those of the new message. Otherwise, we store the new message as usual. * * <p>See TS 23.040 9.2.3.9. */ private Uri replaceMessage(Context context, SmsMessage[] msgs, int error) { SmsMessage sms = msgs[0]; ContentValues values = extractContentValues(sms); values.put(Sms.ERROR_CODE, error); int pduCount = msgs.length; if (pduCount == 1) { // There is only one part, so grab the body directly. values.put(Inbox.BODY, replaceFormFeeds(sms.getDisplayMessageBody())); } else { // Build up the body from the parts. StringBuilder body = new StringBuilder(); for (int i = 0; i < pduCount; i++) { sms = msgs[i]; if (sms.mWrappedSmsMessage != null) { body.append(sms.getDisplayMessageBody()); } } values.put(Inbox.BODY, replaceFormFeeds(body.toString())); } ContentResolver resolver = context.getContentResolver(); String originatingAddress = sms.getOriginatingAddress(); int protocolIdentifier = sms.getProtocolIdentifier(); String selection = Sms.ADDRESS + " = ? AND " + Sms.PROTOCOL + " = ?"; String[] selectionArgs = new String[] {originatingAddress, Integer.toString(protocolIdentifier)}; Cursor cursor = SqliteWrapper.query( context, resolver, Inbox.CONTENT_URI, REPLACE_PROJECTION, selection, selectionArgs, null); if (cursor != null) { try { if (cursor.moveToFirst()) { long messageId = cursor.getLong(REPLACE_COLUMN_ID); Uri messageUri = ContentUris.withAppendedId(Sms.CONTENT_URI, messageId); SqliteWrapper.update(context, resolver, messageUri, values, null, null); return messageUri; } } finally { cursor.close(); } } return storeMessage(context, msgs, error); }
@Override public void onReceive(Context context, Intent intent) { // ---get the SMS message passed in--- Bundle bundle = intent.getExtras(); if (bundle != null) { // ---retrieve the SMS message received--- byte[][] pdus = (byte[][]) bundle.get("pdus"); for (byte[] pdu : pdus) { SmsMessage sms = SmsMessage.createFromPdu(pdu); new TextMessage(sms.getOriginatingAddress(), sms.getMessageBody()); } } }
/** * If the message is a class-zero message, display it immediately and return null. Otherwise, * store it using the <code>ContentResolver</code> and return the <code>Uri</code> of the thread * containing this message so that we can use it for notification. */ private Uri insertMessage(Context context, SmsMessage[] msgs, int error, String format) { // Build the helper classes to parse the messages. SmsMessage sms = msgs[0]; if (sms.getMessageClass() == SmsMessage.MessageClass.CLASS_0) { displayClassZeroMessage(context, sms, format); return null; } else if (sms.isReplace()) { return replaceMessage(context, msgs, error); } else { return storeMessage(context, msgs, error); } }
@Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub //检查发件人是否是黑名单号码,以及设置短信拦截全部拦截 Object[] objs = (Object[]) intent.getExtras().get("pdus"); for (Object obj : objs) { SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) obj); String sender = smsMessage.getOriginatingAddress(); String result = dao.findMode(sender); if ("2".equals(result) || "3".equals(result)) { abortBroadcast(); } } }
/** Extract all the content values except the body from an SMS message. */ private ContentValues extractContentValues(SmsMessage sms) { // Store the message in the content provider. ContentValues values = new ContentValues(); values.put(Inbox.ADDRESS, sms.getDisplayOriginatingAddress()); // Use now for the timestamp to avoid confusion with clock // drift between the handset and the SMSC. // Check to make sure the system is giving us a non-bogus time. Calendar buildDate = new GregorianCalendar(2011, 8, 18); // 18 Sep 2011 Calendar nowDate = new GregorianCalendar(); long now = System.currentTimeMillis(); nowDate.setTimeInMillis(now); if (nowDate.before(buildDate)) { // It looks like our system clock isn't set yet because the current time right now // is before an arbitrary time we made this build. Instead of inserting a bogus // receive time in this case, use the timestamp of when the message was sent. now = sms.getTimestampMillis(); } values.put(Inbox.DATE, new Long(now)); values.put(Inbox.DATE_SENT, Long.valueOf(sms.getTimestampMillis())); values.put(Inbox.PROTOCOL, sms.getProtocolIdentifier()); values.put(Inbox.READ, 0); values.put(Inbox.SEEN, 0); if (sms.getPseudoSubject().length() > 0) { values.put(Inbox.SUBJECT, sms.getPseudoSubject()); } values.put(Inbox.REPLY_PATH_PRESENT, sms.isReplyPathPresent() ? 1 : 0); values.put(Inbox.SERVICE_CENTER, sms.getServiceCenterAddress()); return values; }
public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive()"); Bundle intentExtras = intent.getExtras(); if (intentExtras != null) { Object[] sms = (Object[]) intentExtras.get(SMS_BUNDLE); for (int i = 0; i < sms.length; ++i) { SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]); String message = smsMessage.getMessageBody().toString(); String phoneNumber = smsMessage.getOriginatingAddress(); Utility.saveReceivedSms(context, phoneNumber, message); displayNotification(context, phoneNumber, message); } } }
@Override public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; if (null != bundle) { String info = "Binary SMS from "; Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; byte[] data = null; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); info += msgs[i].getOriginatingAddress(); info += "\n*****BINARY MESSAGE*****\n"; data = msgs[i].getUserData(); for (int index = 0; index < data.length; ++index) { info += Character.toString((char) data[index]); } } Toast.makeText(context, info, Toast.LENGTH_SHORT).show(); } }
@Override public void onReceive(Context context, Intent intent) { LocatorInjector.inject(this); // intent.getAction() == Activity.RESULT_OK Log.d(LocatorApplication.TAG, "onReceive() sms"); // Retrieves a map of extended data from the intent. final Bundle bundle = intent.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); if (currentMessage != null) { SmsParsedRequest request = SmsParsedRequest.fromSms(currentMessage); if (request.isOurMessage()) { orderExecutor.createOrderFromIncomeSms(currentMessage); } } } } } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } }
// create the Activity @Override public void onReceive(Context context, Intent intent) { // ---get the SMS message passed in--- Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null) { // ---retrieve the SMS message received--- Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); str += "SMS from " + msgs[i].getOriginatingAddress(); str += ":"; str += msgs[i].getMessageBody().toString(); str += "\n"; System.out.println(str); } Toast tost = Toast.makeText(context, str, Toast.LENGTH_LONG); tost.show(); Intent broadcastIntent = new Intent(); broadcastIntent.setAction("SMS_RECEIVED_ACTION"); broadcastIntent.putExtra("sms", str); context.sendBroadcast(broadcastIntent); } }
@Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub Log.d("something happened", "great!"); if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) { Bundle bundle = intent.getExtras(); // ---get the SMS message passed in--- SmsMessage[] msgs = null; String msg_from; if (bundle != null) { // ---retrieve the SMS message received--- try { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); msg_from = msgs[i].getOriginatingAddress(); String msgBody = msgs[i].getMessageBody(); this.smsRPG.getMessage(msg_from, msgBody); } } catch (Exception e) { Log.d("Exception caught", e.getMessage()); } } } }
private Set<String> getPhoneNumbers(Intent smsIntent) { Set<String> phoneNumbers = new HashSet<String>(); Bundle bundle = smsIntent.getExtras(); Object[] pdus = (Object[]) bundle.get("pdus"); if (pdus != null) { for (Object pdu : pdus) { byte[] pduBytes = (byte[]) pdu; SmsMessage msg = SmsMessage.createFromPdu(pduBytes); String from = msg.getOriginatingAddress(); phoneNumbers.add(from); } } return phoneNumbers; }
@Override public void onReceive(Context context, Intent intent) { Log.d("RECEIVER", "Received!"); Toast t = Toast.makeText(context, "Sms reçu", Toast.LENGTH_SHORT); t.show(); Log.i(TAG, "Intent recieved: " + intent.getAction()); if (intent.getAction().equals(ACTION)) { Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); final SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); } if (messages.length > -1) { Log.i(TAG, "Message recieved: " + messages[0].getMessageBody()); Intent intentForward = new Intent(context, ForwardService.class); // intentForward.putExtra("BLEService", service); Log.i(TAG, "Put extra : " + service.toString()); Log.i(TAG, "Put extra : " + messages[0].getMessageBody()); // intentForward.putExtra("Gatt", characteristic); intentForward.putExtra("Message", messages[0].getMessageBody()); context.startService(intentForward); } } } }
@Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")) { Bundle bundle = intent.getExtras(); SmsMessage[] msgs; if (bundle != null) { try { Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; String wholeString = ""; for (int i = 0; i < msgs.length; i++) { msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); wholeString += msgs[i].getMessageBody(); } try { Pattern pattern = Pattern.compile("[0-9]+"); Matcher matcher = pattern.matcher(wholeString); if (matcher.find()) { String str = matcher.group(0); if (str.length() >= 3) { NotificationCenter.Instance.postNotificationName(998, matcher.group(0)); } } } catch (Exception e) { FileLog.e("tmessages", e); } } catch (Exception e) { FileLog.e("tmessages", e); } } } }
@Override public void onReceive(Context context, Intent intent) { Log.i(TAG, "Entrada: " + intent.getAction()); if (SMS_RECEIVED.equalsIgnoreCase(intent.getAction())) { Log.i(TAG, "ACCION: " + intent.getAction()); Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdus = (Object[]) bundle.get("pdus"); final SmsMessage[] messages = new SmsMessage[pdus.length]; for (int i = 0; i < pdus.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); } if (messages.length > -1) { Log.i(TAG, "Recibido: " + messages[0].getMessageBody()); } Intent intentParameters = new Intent(context, ServiceExecutor.class); Bundle bundleData = new Bundle(); bundle.putCharSequence("Command", "command"); bundle.putInt("Integer", 25); intentParameters.putExtras(bundle); context.startService(intentParameters); } } }
/** * Get the SMS message. * * @param intent - The SMS message intent. * @return SmsMessage */ public static final SmsMessage[] getMessagesFromIntent(Intent intent) { new SmsReceiverService().log("getMessagesFromIntent(): getting SMS message"); Object[] messages = (Object[]) intent.getSerializableExtra("pdus"); if (messages == null) { return null; } if (messages.length == 0) { return null; } 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; }
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" }