Main white everlink logo
text_snippet Examples
Coming soon
text_snippet Examples
Coming soon

Create ultra-contactless token communication

(!) BEFORE GETTING STARTED

flash_on You should have a token based Android app.

Guide focus: Setting up Everlink’s Android SDK to enable sonic-key to token exchange.

There are two core elements to consider in this process, Set Up and Usage.

Set Up: Please follow the steps below to get started:

  1. Add Everlink SDK to your app in Android Studio
  2. Add the required permissions
  3. Calling the Everlink class

1) Add EverLink SDK to your app

Step 1 requires account approval

2) Permissions

Next you need to add the required permissions to the AndroidManifest.xml file:

       <Manifest>

       <uses-permission android:name="android.permission.RECORD_AUDIO" />
       
       <uses-permission android:name="android.permission.INTERNET" />

       <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

       <Application>
       // Other codes...
       </Application>       
       </Manifest>

      

3) Call the Everlink class

In order to start using Everlink - so that you can receive and send tokens over audio - you have to call the EverLink class, and set its listeners.

Changing the package at the top to the correct package of your project, and string myAppID to your key, which you can find in the account page, and importing the EverLink class from the SDK:


      package com.everlinkdemo;

      // Other codes...

      import com.everlink.broadcast.util.Everlink;

      // Other codes...


      public class MainActivity extends AppCompatActivity {

          private static final int REQUEST_MICROPHONE = 8000;
          private Everlink EverlinkObj;

          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);

             String myAppID = "12345";
              
             //check permissions
             if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.RECORD_AUDIO)
             != PackageManager.PERMISSION_GRANTED ) {
             ActivityCompat.requestPermissions( this, new String[] {
             android.Manifest.permission.RECORD_AUDIO  }, REQUEST_MICROPHONE); }
              
             EverlinkObj = new Everlink(getApplicationContext(), this, myAppID);
             EverlinkObj.setAudioListener(new Everlink.audioListener() {
          
             @Override
             public void onAudioCodeReceived(String token) {
            // you can now identify, via the server returned token, what location/device was heard
                Log.d("newToken", token);
             }

             @Override
             public void onEverlinkError(String error) {
                //return the type of error received: server response, no internet, no permissions
                Log.d("error", error);
             }

             @Override
             public void onMyTokenGenerated(String oldToken, String newToken) {
                //a new token generated, to save in your database
                Log.d("newToken", newToken);
                Log.d("oldToken", oldToken);
             }
             });
              
          }

      }

      

CONGRATS you’ve now set-up Everlink! Now onto usage.


Usage: After the client app is set up, you are ready to begin verifying and identifying devices, you can now:

  1. Detect codes
  2. Send codes
The EverLink class has a number of listeners and methods that you can use to send and receive audio codes. We do all audio code generation, token checks and returns, and stop listening on code detection automatically.

1) Detect Code

When you want to detect an audio code simply call: startListening(isOffline);


      // Other codes...
      listenButton.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
         //to start listening for a code call:

         EverlinkObj.startListening(isOffline);
                    
         }
      });
      // Other codes...
      stopListenButton.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
         //to stop listening call:

         EverlinkObj.stopListening();
                    
         }
      });
      // Other codes...

      
Which will cause the device to start listening for an audio code, on successful detection we will return the identifying token of the heard device via the onAudioCodeReceived listener.

Method startListening(isOffline); now takes a boolean as an argument, If this argument is true then the device will try to do the matching locally with any previously saved tokens, rather than contacting our servers; this will allow your users to be offline.

2) Send Code

When you want to start emitting an audio code simply call: startEmitting();


      // Other codes...
      playButton.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
         //to start emitting an audio code call:

         EverlinkObj.playVolume(0.9, useLoudspeaker); 

         EverlinkObj.startEmitting();
                    
         }
      });
      // Other codes...
      stopButton.setOnClickListener(new View.OnClickListener() {
         public void onClick(View v) {
         ////to stop emitting call:

         EverlinkObj.stopEmitting();
                    
         }
      });
      // Other codes...

      

You can alternatively pass a token as an argument and its audio code will play, as shown below:

      // Other codes...
      playToken.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        //to start emitting an audio code call:
                                         
        EverlinkObj.startEmittingToken("exampleToken12345", isOffline);
                                         
       }

      });
      // Other codes...

      
Method startEmittingToken(token, isOffline); now takes a boolean as an argument. If this argument is true then the device will try to fetch the audio code it will emit locally, rather than contacting our servers, this will allow your users to be offline.

Function playVolume(volume, useLoudspeaker); allows you to set the volume and whether the audio should default to the loudspeaker.

Create token

If you wish to manually generate a new user token call: createNewToken(startDate);


      // Other codes...
      newTokenButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        //Generate a new user token to save in your database
                  
           final String startDate = "";

           EverlinkObj.createNewToken(startDate);
                     
         }

      });
      // Other codes...

      
Function createNewToken(startDate); takes a validity start date in the form ‘YYYY-MM-DD’. The token will be valid for two weeks after this date. If no validity date is provided then it will be the current date.

We will return your identifying token via the onMyTokenGenerated listener.

Downloading Tokens
(Only needed if you want the SDK to work offline)

To download the audio code associated with a token so it can later be played or detected offline, call function saveSounds() passing it an array of tokens:


     // Other codes...
     saveTokenButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        //Save an array of tokens and their corresponding audio codes.
            
            String[] tokensArray = {
                    "exampleToken12345",
                    "exampleToken12346",
                    "exampleToken12347"
            };

                EverlinkObj.saveSounds(tokensArray);
               
        }

     });
     // Other codes...

Call clearSounds(); To delete all downloaded tokens and their corresponding audio codes