Giter VIP home page Giter VIP logo

android-sdk's Introduction

How to Integrate SAWO SDK to an Android app

  1. Add following line to root build.gradle repositories block

    maven { url 'https://jitpack.io' }
  2. Add this to your app level build.gradle android block

       compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    
        kotlinOptions {
            jvmTarget = '1.8'
        }
  3. Add this to your app level build.gradle dependencies block

        implementation 'com.github.sawolabs:Android-SDK:0.1.8'
  4. Sync your project

  5. Go to https://dev.sawolabs.com and create a project and copy the api key and api key secret

  6. Create an Activity in Android Studio to get login success response for this example lets assume it is CallbackActivity

  7. In your MainActivity add a button to login and add following code to its onclick handle

    Java

    import com.sawolabs.androidsdk.Sawo;
    
    public void onClickLogin(View view) {
        new Sawo(
                    this, 
                    "", // your api key
     	   "" // your api key secret
                    ).login(
                    "email", // can be one of 'email' or 'phone_number_sms'
                    CallbackActivity.class.getName()  // Callback class name
            );
    }

    Kotlin

    import com.sawolabs.androidsdk.Sawo
    
    fun onClickLogin(view: View) {
            Sawo(
                this,
                "", // your api key
                "" // your api key secret
            ).login(
                "email", // can be one of 'email' or 'phone_number_sms'
                CallbackActivity::class.java.name // Callback class name
            )
        }
  8. Get the response payload in the CallbackActivity

    Java

    import com.sawolabs.androidsdk.ConstantsKt;
    
    Intent intent = getIntent();
    String message = intent.getStringExtra(ConstantsKt.LOGIN_SUCCESS_MESSAGE);
    
    // continue with your implementation

    Kotlin

    import com.sawolabs.androidsdk.LOGIN_SUCCESS_MESSAGE
    
    val message = intent.getStringExtra(LOGIN_SUCCESS_MESSAGE)
    // continue with your implementation
  9. Recommended: Verify the payload sent by sdk from your backend

    Python example:

    import requests
    
    data = {
        'user_id': payload_sent_from_sdk['user_id']
    }
    res = requests.post('https://api.sawolabs.com/api/v1/userverify/', data=data)
    # Match the verification token in response with sdk payload
    if res.status_code == 200:
        response_data = res.json()
        if response_data['verification_token'] \
                    == payload_sent_from_sdk['verification_token']:
                # continue with your implementation for example add the user to your db

android-sdk's People

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.