Menu

PlayBasis android sdk sample

In this article, we will go to through what's inside playbasis android SDK along with it's sample apps than were created to give developers guidelines on developing their own applications.

Download Sample Android App

Playbasis android sample project, consist of the android sdk itself and sample apps.

The sample apps are as the following list.

  • - Get player info Demo
  • - Reward Store Demo
  • - Quest Demo
  • - Quiz Demo
  • - Badge Demo

This code use a sample end-point. By this way you don't have to configure anything on the dashboard for test the code. For work with the sample end-point, the API_KEY is “3416989394” and API_SECRET is “b1fa1529410702557a6fe2f3913768a0”

Setting up sample key

This part is not require for the sample end-point.

If you want to use your own endpoint you should replace the sample api_key and api_secret. Open the AndroidManifest.xml file and change the apikey and secret, meta-data value with your own key.

<meta-data
            android:name="com.playbasis.android.playbasissdk.apikey"
            android:value="\ 3416989394" />
        <meta-data
            android:name="com.playbasis.android.playbasissdk.secret"
            android:value="\ b1fa1529410702557a6fe2f3913768a0" />

A best practice is to create a String resource file with these key, and referee to it on meta-data value. If you write the key directly on the manifest file, keep “\ ” at the beginning. It's force the manifest to read the meta-data value as string.

Last step, on the SampleActivity.java, delete the .setBackendUrl("https://api-sandbox.pbapp.net/") method from Playbasis.Builder.

playbasis = new Playbasis.Builder(this)
                .build();
Sample Apps

Run the sample code, the application directly the Main Activity. This one contain five buttons:

  • - PLAYER
  • - REWARD
  • - QUEST
  • - QUIZ
  • - BADGE

With these buttons you can select the sample application you want to play around.

Player demo

This example demonstrate how to make a simple request to playbasis server.

This demo get the public data of a player and display them into the view.

The view can be empty during one or two second, the time the request need to succeed. Has you can see, playbasis SDK provide a simple networkImageView. You can look on the sample how to use it.

Reward demo

Reward store consists of rewards that can be redeemed. It will send the redeemed coupon code back to user. With the coupon, points, experience and badge can be redeemed.

- The “Point and badge” reward, redeem a coupon code with a badge an points.

- The “Points Good” reward, redeem a coupon code with points.

Click on “REWARD” button a redeem a reward.

Quest demo:

This demo demonstrate how users follow through its mission thus complete it one by one.

On this demo the user already join the quest. If you use your own quests, you have to join them before complete the missions. For join all available quests for the player, use this method:

QuestApi.joinAll(SampleApplication.playbasis, "exampleplayer", new OnResult<Map<String, Object>>() {
            @Override
            public void onSuccess(Map<String, Object> result) {
            }
            @Override
            public void onError(HttpError error) {
            }
        } );

The details of the current quest are display under “Quest” section. The “Missions” section contain the list of available missions. To do suck an action press the right mission button. A dialog fragment are display with the rewards when the mission is accomplish. Once it's done, the mission is display in green and you can't preform it again.

Quiz Demo

This demo demonstrate how users get a quiz, and then answer questions one by one, for finally get a reward.

First select a quiz:

Then answer the first question:

Answer the second question:

The quiz is finish and you get a reward:

Badge Demo

Badge demo demonstrate how such a rule setting up in playbasis Dashboard work with user's application. The rule is to do “onclick” UIEvent, then user will get a badge reward. When you click the button, an “onclick” event is processed, and the result displayed on a dialog fragment.