Coder Social home page Coder Social logo

smsreceiver's Introduction

SMSReceiver

Dokumentasi versi Bahasa Indonesia README_ID.md

A Simple library to receive sms. Can be used for OTP-SMS handling.

Support API Level >= 9

OTP-SMS is commonly used to verify user registration in Android application. This library simplify the process to receive the SMS registration so developer don't need to implement SMS receiver to receive the broadcast message by the Android.

Only need 5 lines of codes to receive the sms!

How to use

Step 1. Add the JitPack repository in your root build.gradle at the end of repositories:

allprojects {
        repositories {
               ...
               maven { url "https://jitpack.io" }
        }
}

Step 2. Add the dependency

implementation 'com.github.joielechong:smsreceiver:0.9'

Step 3. Add the receiver

 // Start to receive the sms
 SmsReceiver.getInstance().register();
 SmsReceiver.getInstance().initialize();

 SmsReceiver.getInstance().setResultListener(new SmsReceiver.ResultListener() {
    @Override
    public void onSmsReceived(String sender, String message) {
         Toast.makeText(getBaseContext(),
                         "Sender = " + sender + ", " + "Message = " + message,
                         Toast.LENGTH_SHORT).show();
    }
  });

Step 4. Stop receiving the sms You can stop receiving sms anytime. When in an Activity, you can stop receiving sms when the Activity is stopped or destroyed:

 @Override
 protected void onDestroy() {
     super.onDestroy();
     SmsReceiver.getInstance().unregister();
 }

Configuration to receive SMS

  • To receive all sms you only need to use the following:

       SmsReceiver.getInstance().initialize();
    
  • To receive sms only from specific numbers, you can use the following:

       SmsReceiver.getInstance().initialize("082368636477");
    
       // Or
       SmsReceiver.getInstance().initialize("082368636477", "082368636478");
    

    you can specify any number as you want. There is no limitation of total number arguments.

  • To receive sms from any number but with specific text constraint, for example, when waiting for OTP-SMS with the following format:

     Application activation code is GA-12345.
    

    where the activation code is GA-12345. You can use the following:

         SmsReceiver.getInstance().initialize("GA", "", "12345");
    
  • You can also receive the activation code as the above regardless of the sender number with:

         SmsReceiver.getInstance().initialize("GA", "");
    

Developed By

License

Copyright 2018 Joielechong

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

smsreceiver's People

Contributors

joielechong avatar

Stargazers

T.A.Z avatar akbarwibawa avatar

Watchers

akbarwibawa avatar  avatar Rendy ariawindana avatar

Forkers

anggerridho

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.