Initialization
In order to access the functionalities of the AppsPrize Playtime SDK, it is necessary to perform an initialization process. To achieve this, simply make a call to Application class initialize(Context,AppsPrizeConfig,AppsPrizeListener)
The initialization will occur asynchronously in the main application process, running in the background. Upon completion, you will be notified through the AppsPrizeListener
's onInitialize
or onInitializedFailed
method, depending on the outcome.
public class MainApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
AppsPrizeConfig config = new AppsPrizeConfig.Builder()
.build(APPS_PRIZE_APP_TOKEN, ADVERTISING_ID, USER_ID);
AppsPrize.initialize(getApplicationContext(), config, new AppsPrizeListener() {
@Override
public void onInitialize() {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onInitialize");
}
@Override
public void onInitializeFailed(@NonNull String errorMessage) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onInitializeFailed: err: " + errorMessage);
}
@Override
public void onRewardUpdate(@NonNull List<AppReward> rewards) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onRewardUpdate: " + rewards);
}
});
}
}
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
val config = AppsPrizeConfig.Builder()
.build(APPS_PRIZE_APP_TOKEN, ADVERTISING_ID, USER_ID)
AppsPrize.initialize(applicationContext, config, object : AppsPrizeListener {
override fun onInitialize() {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onInitialize")
}
override fun onInitializeFailed(errorMessage: String) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onInitializeFailed: err: $errorMessage")
}
override fun onRewardUpdate(rewards: List<AppReward>) {
Log.d("[AppsPrize]", "MainApplication:onCreate AppsPrize:onRewardUpdate: $rewards")
}
})
}
}
The parameters to this call are as follows:
- Context: Your application's
context
. - AppsPrizeConfig: An object to pass additional options to the AppsPrize SDK when initializing. This parameter is a must and you can call
initialize(Context, AppsPrizeConfig)
orinitialize(Context, AppsPrizeConfig, AppsPrizeListener)
instead. - AppsPrizeListener: A listener which informs you about whether the AppsPrize Playtime SDK was initialized successfully or not. This parameter is optional and you can call
initialize(Context,AppsPrizeConfig)
orinitialize(Context, AppsPrizeConfig, AppsPrizeConfig)
instead.
You can create an AppsPrizeConfig
object in the following way:
AppsPrizeConfig
data class AppsPrizeConfig
This class holds the configuration information of AppsPrize
Functions
- Build
fun build(token: String, advertisingId: String, userId: String): AppsPrizeConfig
This function builds AppsPrizeConfig with the current properties
Return
AppsPrizeConfig instance
Parameters
token: AppsPrize token provided once you sign up and add your app to dashboard (https://dashboard.appsprize.com).
advertisingId: Google advertising id from device.
userId: App unique user ID
-
setCountry/setLanguage
val config = AppsPrizeConfig.Builder() .setCountry("ES") //set as null or not set for default .setLanguage("es") //set as null or not set for default
Device-locale is used for country and language default. We need to get these functions from the app in order to target offers according to end user location.
- setForegroundServiceEnabled
fun setForegroundServiceEnabled(foregroundServiceActive: Boolean?): AppsPrizeConfig.Builder
This function allows to set foreground service enabled/disabled If set null or not set will use true.
And for the AppsPrizeListener
;
AppsPrizeListener
interface AppsPrizeListener
This interface represents AppsPrizeListener
which notifies applications when an event occurs about AppsPrize.
Functions
- onInitialize
open fun onInitialize()
This function will let you know that AppsPrize initialization is completed.
- onInitializedFailed
open fun onInitializeFailed(errorMessage: String)
This function will let you know that AppsPrize initialization has failed to complete.
Parameters
errorMessage: Error message of the load fail reason.
- onRewardUpdate
open fun onRewardUpdate(rewards: List<AppReward>)
This function will let you know that the user has completed one or multiple rewards in a session.
Parameters
rewards: List of rewards earned by user.
Updated 17 days ago