SDK Guide
For Mobile Apps/Games
Android
11 min
this guide is for anyone who wishes to integrate the enefits mobile sdk into an android native app before continuing, we highly recommend reviewing the general usage guide to familiarize yourself with general sdk workflow concepts before continuing you will need to generate an api key with your enefits account before continuing with integration to obtain an api key, simply register at http //enefits co http //enefits co , go to developer in the account menu in the top right section from there, generate an api key and save this for all api requests as defined below we only show this once so if you lose this api key, you’ll have to re generate from the developer section run the demo to run a live demo, visit https //bajaar beanstalkapp com/enefits mobile sdk?ref=b androidv1 0 https //bajaar beanstalkapp com/enefits mobile sdk?ref=b androidv1 0 and provide your own api key where requested download the sdk the enefits android sdk can be downloaded from https //bajaar beanstalkapp com/enefits mobile sdk?ref=b androidv1 0 https //bajaar beanstalkapp com/enefits mobile sdk?ref=b androidv1 0 installation add the @jitpack repository to your gradle file repositories { 	 	maven { url 'https //jitpack io' } } add these dependencies in your project gradle along with aar file dependencies { // coroutines implementation 'org jetbrains kotlinx\ kotlinx coroutines core 1 6 1' implementation 'org jetbrains kotlinx\ kotlinx coroutines android 1 6 1' // walletconnect implementation 'com github walletconnect\ kotlin walletconnect lib 0 9 8' implementation 'com github komputing\ khex 1 1 2' // json implementation 'com squareup moshi\ moshi adapters 1 13 0' implementation 'com squareup moshi\ moshi kotlin 1 13 0' // http implementation 'com squareup okhttp3\ okhttp 5 0 0 alpha 3' implementation 'com google code gson\ gson 2 9 1' } sdk setup initialize the sdk enefits instance init(context, your api key here, your app name here, sesssioncallback) sessioncallback class myactivity appcompatactivity(), enefits enefitssessioncallback { override fun onsessionconnected(address string, blockchaininfo jsonobject) { runonuithread(runnable { toast maketext(this, "connected with $address", toast length short) show() }) } override fun onsessiondisconnected() { runonuithread(runnable { toast maketext(this, "disconnected ", toast length short) show() }) } override fun onappinstalledornot(isappinstalled boolean) { runonuithread(runnable { if (!isappinstalled) { toast maketext(this,"no supported wallets installed on this device",toast length short) show() } }) } } connect wallet display a button or call to action (for example connect wallet) which when pressed or clicked will prompt the user to connect a wallet after the user selects a wallet and initiates a session, the returned address will be available to the enefits sdk to check nfts and any offers the user is eligible for this function will open a popup with a list of supported providers (eg metamask, trust wallet, rainbow, etc) based their apps as installed on the device enefits sdk will fire the callback onsessionconnected after successfully connecting with a blockchain account if connection fails, the callback onsessiondisconnected will be fired enefits instance connectaccount() get all enefits offers this method will return all offers that the user is eligible for based on the address they provided when they connected their wallet based on the response from this method and the existence of a specific id value that the mobile app is looking for, your app logic will handle accordingly enefits instance getoffers() helper functions use the functions provided below to create a tighter integration with the enefits sdk and manage user connectivity states / check if enefits sdk has successfully initialised @return boolean / enefits instance isinitcomplete() / check if enefits sdk was able to connect to a blockchain account @return boolean / enefits instance isaccountconnected() / get the address of the connected account @return string / enefits instance getconnectedaccount() / get the blockchain info for the connected account @return jsonobject / enefits instance getchaindata() / disconnect from the blockchain account on successful disconnect, enefits fires callback event onsessiondisconnected / enefits instance disconnect()