Adding authentication and iBeacon offers to your Android app
In this entry the goal will be to create a simple application using the requests of the Piggate SDK for Android to register new users to our platform or login if there is an account already created. For this entry we need to use the Piggate Dashboard to create our application and add the group offers to our Android application.
Once all of the above is done and when we have set the Application ID we will have our Android app linked to our Dashboard and when a beacon is discovered, it will show the offers.
Creating your iBeacon
First of all, go to the Piggate dashboard and in the iBeacons sections create many iBeacon as you want to use. The fields that we need are the beacon name, the type (in this case iBeacon), the major and the minor, and place them in the map:
Creating the campaign
Go to the Campaign section and create the campaign which will contain all the offers. You have to set the name and description fields, a notification message and the secret and publishable key for your stripe account integration (this will be explained in another post):
Creating the offers
Go to the content section and create a new offer by clicking in tickets and creating a new one. First of all set the name, description, URL for the image, price and related campaign:
After this, set the unlock code, currency, and the secret and publishable keys set before:
Now place the store which will apear like a green marker and activate your iBeacon by clicking it:
If you want, create more offer tickets to show with your iBeacons.
Creating the application in the Piggate Dashboard
In the Apps section create a new application, like in the following image, setting the name, description, icon image URL and campaign:
Link the dashboard app to your Android app
Edit the app created before and copy the Application ID, that will appear in the top like in the following capture:
Copy this ID and in the AndroidManifest.xml of your Android application add the following lines:
With all the steps finished the application and the dashboard are linked and we can do the login and register requests, so we can get the offers to show them with our iBeacons.
Create the login and register screens
Once all of the above is done, we only have to create two activities, one for the login and another for the register, with two fields: the email and the password.
When the EditText fields and the button are done, we are ready to set the onClick listener of the button:
Inside this onClick method we need to get the email and password, put them into a RequestParams object:
Then, with the Piggate objet, set the login request, called RequestOpenSession. Inside the listener we have to override the onComplete and onError methods for JSONObject and JSONArray (Activity_SingIn is the activity where we do the login request, and Activity_logged is the next activity):
The register screen works exactly as the login screen, using the RequestNewUser instead of RequestOpenSession request:
Create the logged activity and get the offers
In this screen we can have a button to do a logout request like the login and register buttons. To use this request we can call the following Piggate request, which have the same methods as the above ones:
On the other hand, it’s necessary to get the list of iBeacons whose offers we need to get with two simple functions:
With all of this done, the user can register and login into the application and get the nearby offers to their corresponding iBeacons and show as he wants.
If you don’t want to code…
We have a complete example (called Piggate Offers Demo) which allows you to see the nearby offers, buy them with Stripe and exchange them, with a fancy looking interface. You can download the examples in our GitHub page and see what can be done with our tools.
To use the complete example you only have to create your application with campaign and offers, add your own iBeacons to the Piggate dashboard and activate them. Now get your Application ID and Stripe publishable key and put them in the AndroidManifest.xml of the Android application. Once you do this steps the application will works with your created offers and iBeacons.
Enjoy our tools and feel free to write a comment and send us feedback!