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
Step 1 requires account approval
<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); } }); } }
Usage: After the client app is set up, you are ready to begin verifying and identifying devices, you can now:
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.
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...
// 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.
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.
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