SMS Parser Android


Source link: https://github.com/adorsys/sms-parser-android

SMS Parser - Android

Receiving and Parsing SMS Messages on Android Devices

Introduction

This module was created for getting specific codes out of incoming SMS messages. To use it you create a Config object where you specify the BEGIN and END message phrases & the SMS sender numbers from which you want to read the sms content. The received code then can be used according to your need (activation, authentication etc...).

How it Works

If you get a SMS message like this:

This is an automated message used by X-App. You can delete this message at any time. BEGIN-MESSAGE 08ff08d3b2981eb6c611a385ffa4f865 END-MESSAGE 

and the sender of the message is one of the numbers you have specified in your Config object the parsing process will begin.

First the module reads the whole message. It then checks if it contains the BEGIN and END phrases you specified. If it does then it takes only the part that is between those phrases and send a broadcast to you app with the specific code and the sender phone number. In this case the module would send a broadcast containing 08ff08d3b2981eb6c611a385ffa4f865 and the sender number.

For more info read Usage.

Usage

Add the module to your apps build.gradle:

compile 'de.adorsys.android:smsparser:0.0.3'

First of all you have to create a Config object to configure the modules use:


  SmsConfig.INSTANCE.initializeSmsConfig(

  "BEGIN-MESSAGE",

  "END-MESSAGE",

  "0900123456", "0900654321", "0900900900");

Here the two parameters are the keywords that will be used for the code to be extracted from the sms message. The third parameter is a varargs (...) parameter, where you can give a series of phone numbers (as Strings), which will be checked against for reading sms content.

Then before startinganything you have to aks for the SMS Permmision on Android 6.0 and higher, or else the module won't work:


  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {

 SmsTool.requestSMSPermission(Context);

}

Then you need to create a LocalBroadcastManager and BroadcastReceiver, like this:

 @NonNull
  private LocalBroadcastManager localBroadcastManager;

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

@Override

public void onReceive(Context context, Intent intent) {

 if (intent.getAction().equals(SmsReceiver.INTENT_ACTION_SMS)) {

  String receivedSender = intent.getStringExtra(SmsReceiver.KEY_SMS_SENDER);

  String receivedMessage = intent.getStringExtra(SmsReceiver.KEY_SMS_MESSAGE);

  smsSenderTextView.setText(getString(R.string.text_sms_sender_number,

 receivedSender != null ? receivedSender : "NO NUMBER"));

  smsMessageTextView.setText(getString(R.string.text_sms_message,

 receivedMessage != null ? receivedMessage : "NO MESSAGE"));

 
}

}

  
}
;

LocalBroadcastManager is used instead of standard BroadcastManager for security reasons, so no other app can listen to the broadcasts that are sent.

You must create register and unregister methods for the BroadcastReceiver and call them in onResume() and onPause(), respectively:

 @Override
  protected void onResume() {

registerReceiver();

super.onResume();

  
}

 @Override
  protected void onPause() {

unRegisterReceiver();

super.onPause();

  
}

private void registerReceiver() {

localBroadcastManager = LocalBroadcastManager.getInstance(Context);

IntentFilter intentFilter = new IntentFilter();

intentFilter.addAction(SmsReceiver.INTENT_ACTION_SMS);

localBroadcastManager.registerReceiver(broadcastReceiver, intentFilter);

  
}

private void unRegisterReceiver() {

localBroadcastManager.unregisterReceiver(broadcastReceiver);

  
}

Contributors:

@drilonreqica

@itsmortoncornelius

Resources

Custom ImageView for moving image around the screen.

Custom ImageView for android with polygon shape.

There are 3 basic effects:

  • RegularPolygonShape
  • PaperPolygonShape
  • StarPolygonShape

Custom layout that arranges views in rows and columns automatically. Takes care about padding, margins, gravity and layout child gravities.

Super fast and easy way to create header for Android RecyclerView.

An Android library introducing a stack of Views with the first item being flippable.

This is a simple library for integration with Disqus on Android.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes