Code Monkey home page Code Monkey logo

africastalking-android's Introduction

Africa's Talking

Download

This SDK simplifies the integration of Africa's Talking APIs into your Android apps. For better security, the SDK is split into two components: A server module that stores API keys, SIP credentials and other secrets. And a client module that runs in your app. This client module gets secrets from the server component (via RPC), and uses them to interact with the various APIs.

For instance, to send an SMS, the client with request a token from the server; The server will use it's API key to request a token from Africa's Talking on behalf of the client. It will then forward the token to the client which will use it to request the SMS API to send a text. All in a split second!

Usage

Your server application could be something like this:

/* On The Server (Java, Node.js, PHP, C/C++, C# and all languages supported by gRPC.) */

import com.africastalking.*;

public class SomeJavaApplication {

    public static void main(String[] args) {
    
        // Initialize the SDK
        AfricasTalking.initialize(USERNAME, API_KEY);
        
        // Initialize the server
        Server server = new Server();
        
        // Add SIP credentials (Voice Only)
        server.addSipCredentials(SIP_USERNAME, SIP_PASSWORD, SIP_HOST);
        
        // Start the server
        server.start();
    }
}

And your Android app:

/* On The Client (Android) */
public class SomeActivity extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(args);
        setContentView(R.layout.some_activity);
        
        // Init SDK
        AfricasTalking.initialize(SERVER_HOSTNAME);
       
        // Get Service
        AirtimeService airtime = AfricasTalking.getAirtimeService();

        // Use Service
        airtime.send("+25467675655", "KES", 100, new Callback<AirtimeResponses>() {
          @Override
          void onSuccess(AirtimeResponses responses) {
            //...
          }

          @Override
          void onError(Throwable throwable) {
            //...
          }
        });
    }
}

See the example for complete sample apps (Android, Web Java+Node)

Download

Server

Node

npm install --save africastalking

Java

repositories {
  maven {
    url  "http://dl.bintray.com/africastalking/java"
  }
}
dependencies{
  compile 'com.africastalking:server:VERSION'
}

Or Maven (from http://dl.bintray.com/africastalking/java)

<dependency>
  <groupId>com.africastalking</groupId>
  <artifactId>server</artifactId>
  <version>VERSION</version>
</dependency>

Client (Android)

android {

    // ...
    
    defaultConfig {
        
        // ...
        
        ndk {
            abiFilters "armeabi", "x86"
        }
    }
}

repositories {
  maven {
    url  "http://dl.bintray.com/africastalking/android"
  }
}
dependencies{
  compile 'com.africastalking:client:VERSION'
  // or
  compile 'com.africastalking:client-ui:VERSION' // with checkout UI for payment
}

Initialization

The following static methods are available on the AfricasTalking class to initialize the library:

  • initialize(String host, int port, bool disableTLS): Initialize the library.
  • getXXXService(): Get an instance to a given XXX service. e.g. AfricasTalking.getSmsService(), AfricasTalking.getPaymentService(), etc.

Services

All methods are synchronous (i.e. will block current thread) but provide asynchronous variants that take a Callback<T> as the last argument.

Account

  • getUser(): Get user information.

Airtime

  • send(String phone, String currencyCode, float amount): Send airtime to a phone number.

  • send(HashMap<String, String> recipients): Send airtime to a bunch of phone numbers. The keys in the recipients map are phone numbers while the values are airtime amounts ( e.g. KES 678).

For more information about status notification, please read http://docs.africastalking.com/airtime/callback

Token

  • createCheckoutToken(String phoneNumber): Create a checkout token.

SMS

  • send(String message, String[] recipients): Send a message

  • sendBulk(String message, String[] recipients): Send a message in bulk

  • sendPremium(String message, String keyword, String linkId, String[] recipients): Send a premium SMS

  • fetchMessage(): Fetch your messages

  • fetchSubscription(String shortCode, String keyword): Fetch your premium subscription data

  • createSubscription(String shortCode, String keyword, String phoneNumber): Create a premium subscription

For more information on:

Payment

  • checkout(CheckoutRequest request): Initiate checkout(mobile, card or bank).

  • validateCheckout(CheckoutValidateRequest request): Validate checkout (card or bank).

  • mobileB2C(String productName, List<Consumer> recipients): Send money to consumer.

  • mobileB2B(String productName, Business recipient): Send money to business.

  • bankTransfer(String productName, List<Bank> recipients): Move money form payment wallet to bank account.

Voice

Unlike other services, voice is initialized as follows:

AfricasTalking.initializeVoiceService(Context cxt, RegistrationListener listener, new Callback<VoiceService>() {
    @Override
    public void onSuccess(VoiceService service) {
      // keep a reference to the 'service'
    }

    @Override
    public void onFailure(Throwable throwable) {
      // something blew up
    }
});
  • registerCallListener(CallListener listener):

  • makeCall(String phoneNumber):

  • picCall():

  • holdCall():

  • resumeCall():

  • endCall():

  • sendDtmf(char character):

  • startAudio():

  • toggleMute():

  • setSpeakerMode(Context context, boolean loudSpeaker):

  • isCallInProgress():

  • getCallInfo()

  • queueStatus(String phoneNumbers):

  • mediaUpload(String url):

Requirements

On Android, This SDK requires API 16+. Your app will also need the following permissions:

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET" />
    
    <!-- The following are required if you want use the voice service -->
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    
    <!-- ... -->
    
</manifest>

For more info, please visit https://www.africastalking.com

africastalking-android's People

Contributors

aksalj avatar jaykayitare avatar

Watchers

James Cloos avatar Davis Osiemo avatar  avatar

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.