Getting Started

This is the documentation for the Java playPORTAL SDK. For an example app using this SDK, check out this repository.

Reference the Learn section for more how to information.

Installation - Guide

To install the Android SDK two things need to be added into your project. First you want to add the code below to your project level build.gradle file.

repositories {
maven{url "https://playportal-studio.bintray.com/maven"}
}

after that is done, add whats below to your app/module level build.gradle file.

implementation 'com.dynepic.ppsdk_android:ppsdk_android:0.0.12@aar'

After completing installation follow the Starting up the SDK guide below.

Starting up the SDK

Initialize the playPORTAL manager (PPManager)

The PPManager needs to be initialized before use. This can be done in your startup activity that's run prior to any operations being requested from the playPORTAL cloud. The example belows shows a code snippet in a "StartupActivity.java" onCreate() method that performs all necessary init.

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CONTEXT = this; //getApplicationContext()
ACTIVITY_CONTEXT = this;
PPManager ppManager = PPManager.getInstance();
ppManager.setContextAndActivity(CONTEXT, ACTIVITY_CONTEXT);
ppManager.addAuthListener((Boolean isAuthd) -> {
// add auth listener - in this case a lambda function that presents a login dialog if user is not auth'd
if (!isAuthd) {
Intent intent = new Intent(CONTEXT, LoginActivity.class);
CONTEXT.startActivity(intent);
ACTIVITY_CONTEXT.finish();
}
});
//Configure SDK and check auth state
ppManager.configure("your-client-id",
"your-client-secret",
"appname://redirect",
"SANDBOX",
"appname",
(status) -> {
// lambda function to catch configure response
if (ppManager.isAuthenticated() && ppManager.getUserData().hasUser()) {
Intent intent = new Intent(CONTEXT, UserProfileActivity.class);
CONTEXT.startActivity(intent);
ACTIVITY_CONTEXT.finish();
} else {
Intent intent = new Intent(CONTEXT, LoginActivity.class);
CONTEXT.startActivity(intent);
ACTIVITY_CONTEXT.finish();
}
});
}

Callbacks

The SDK API calls are asynchronous. These calls invoke user callbacks upon completion of the operation to return status and/or data. To simplify the handling of these callbacks, several callback types are defined.

public interface _CallbackFunction {
public interface _Data {
public void f(@Nullable JsonObject data, @Nullable String error);
}
public interface _Friends {
public void f(@Nullable ArrayList<User> friends, @Nullable String error);
}
public interface _Auth {
public void f(Boolean authState);
}
public interface _Leaderboard {
public void f(@Nullable Leaderboard data, @Nullable String error);
}
public interface _Generic {
public void f(Boolean state);
}
public interface _GenericWithError {
public void f(Boolean state, @Nullable String error);
}
}
NB: @Nullable is Java syntax for an optional parameter.