-
public class S2OfferwallThe S2Offerwall class provides methods for interacting with the S2 Offerwall SDK. It allows you to initialize the SDK, set user information, display offerwalls, and manage user consent for data collection.
Key functionalities include:
- Initializing the SDK using initSdk or initSdk.
- Setting and retrieving the user's unique identifier (username) using setUserName and getUserName.
- Starting the offerwall activity using startActivity or startActivity.
- Managing user consent for personalized ads through methods like setConsentDialogRequired, isConsentDialogRequired, setConsentAgreed, isConsentAgreed, and showConsentDialog.
- Setting a global event listener for offerwall events using setEventListener.
- Retrieving the current Advertising ID using getADID.
- Setting a custom App ID using setAppId.
The SDK requires initialization before most of its features can be used. It's recommended to initialize the SDK early in your application's lifecycle, typically in the
{@code onCreate}method of your Application class or main Activity.User consent is an important aspect. The SDK provides mechanisms to display a consent dialog to users and record their preferences. You can control whether the consent dialog is shown and customize its appearance.
The offerwall can be displayed in different ways, including as a standard activity or as a popup-style activity. You can also specify a placement name to display a specific offerwall configuration. The special placement name MAIN refers to the main offerwall.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfaceS2Offerwall.InitializeListenerpublic interfaceS2Offerwall.EventListener
-
Field Summary
Fields Modifier and Type Field Description public final static StringMAINpublic static intbackgroundColorstatic S2Offerwall.EventListenereventListener
-
Method Summary
Modifier and Type Method Description static voidsetEventListener(S2Offerwall.EventListener listener)Sets the default EventListener for the S2 Offerwall. static StringrequestOfferwallData(Context context, String placementName, boolean isEmbeded)static StringrequestMaxPointData(Context context)static StringgetADID()Retrieves the current Advertising ID (ADID). static voidsetUserName(Context context, String userName)Sets the unique identifier (username) for the user interacting with the offerwall.This username is stored in SharedPreferences and used to identify the userin offerwall requests. static voidsetUserName(Context context, String userName, String displayName)Sets the unique identifier for the user. static voidresetUserName(Context context)Resets the currently set username. static StringgetUserName(Context context)Retrieves the current user name.The user name is stored in SharedPreferences. static StringgetUserDisplayName(Context context)static voidsetAppId(Context context, String appId)Set App ID.App ID is an unique identifier for each app, issued by S2 platform.The s2_app_id value set in AndroidManifest.xml is applied by default,but if this method is called, the value set here takes precedence. static StringgetAppId(Context context)static voidsetConsentDialogRequired(Context context, boolean required)Set whether the consent dialog is required.If set to true and the user has not explicitly agreed with it,the consent dialog will be shown before displaying the offerwall.If set to false, the consent dialog will be skipped. static booleanisConsentDialogRequired(Context context)Checks if the consent dialog is required.The consent dialog is required if the user has not explicitly agreed with it. static voidsetConsentAgreed(Context context, boolean agreed)Sets the user's consent status for data collection and personalized advertising.This preference is stored in SharedPreferences. static booleanisConsentAgreed(Context context)Checks if the user has agreed to the consent for data collection and personalized advertising.This preference is read from SharedPreferences. static booleanisConsentRequired(Context context)Checks if user consent is required. static voidcloseTop()Closes the top-most activity in the activity stack managed by the SDK.This is typically used to programmatically close an offerwall activityor any other activity presented by the SDK. static voidcloseAll()Closes all activities managed by the S2 Offerwall SDK.This method is typically used to ensure that all SDK-related activitiesare properly closed, for example, when the host application is exitingor when a specific user flow requires all offerwall activities to be dismissed. static voidstartActivity(Activity activity, String placementName)Start a S2OfferwallActivity with isPoppupStyle is false. static voidstartActivity(Activity activity, String placementName, boolean isPopupStyle)Start a S2OfferwallActivity. static voidopenAdItem(Activity activity, long advId, boolean needDetail, String placementFrom)static voidinitSdk(Context context)static booleanisInitialized()static voidinitSdk(Context context, S2Offerwall.InitializeListener listener)static voidshowConsentDialog(Activity activity, int resIdDialogLayout, int resIdButtonAgree, int resIdButtonDeny, Runnable onAgree)static voidshowConsentDialog(Activity activity, Runnable onAgree, Runnable onDeny)static voidshowConsentDialog(Activity activity, Runnable onAgree)static voidshowConsentDialog(Activity activity, int resIdDialogLayout, int resIdButtonAgree, int resIdButtonDeny, Runnable onAgree, Runnable onDeny)-
-
Method Detail
-
setEventListener
static void setEventListener(S2Offerwall.EventListener listener)
Sets the default EventListener for the S2 Offerwall.This listener will be invoked for offerwall events if no specific listeneris set for an individual
{@code S2OfferwallView}.The
{@code EventListener}provides callbacks for various events such as:- onLoginRequested: Called when a login action is requested within the offerwall.
- onCloseRequested: Called when a close action is requested within the offerwall.
- onPermissionRequested: Called when the offerwall requires a specific permission (e.g., for attaching images in inquiries).
- Parameters:
listener- The EventListener to be set as the default.
-
requestOfferwallData
static String requestOfferwallData(Context context, String placementName, boolean isEmbeded)
-
requestMaxPointData
static String requestMaxPointData(Context context)
-
getADID
static String getADID()
Retrieves the current Advertising ID (ADID).
The Advertising ID is a unique, user-resettable ID for advertising,provided by Google Play services. This method returns the ADID if the SDKhas been initialized and is able to retrieve it.
It's important to note that the availability of the ADID depends onfactors such as user settings (e.g., if the user has opted out of adpersonalization) and the presence of Google Play services on the device.
-
setUserName
static void setUserName(Context context, String userName)
Sets the unique identifier (username) for the user interacting with the offerwall.This username is stored in SharedPreferences and used to identify the userin offerwall requests.
If the SDK has been initialized, this method will also notify anyobserving
{@code S2OfferwallView}instances about the username change.- Parameters:
context- The context, used to access SharedPreferences.This should typically be an Activity or Application context.userName- The unique identifier for the user.
-
setUserName
static void setUserName(Context context, String userName, String displayName)
Sets the unique identifier for the user.
This identifier, often referred to as a username or user ID, is crucial for tracking userparticipation and rewards within the offerwall. The value is stored locally in SharedPreferences and included in all subsequent requests to the S2 server.
For user privacy and security, it is strongly recommended to use a hashed or encryptedvalue rather than a plain text identifier.
Calling this method also updates any active
{@code S2OfferwallView}instances to reflectthe new user identifier.- Parameters:
context- The context, used to access SharedPreferences.An Activity or Application context is suitable.userName- The unique identifier for the user.displayName- The display name for the user.
-
resetUserName
static void resetUserName(Context context)
Resets the currently set username.This is equivalent to calling setUserName with an empty string.
- Parameters:
context- The context, used to access SharedPreferences.
-
getUserName
static String getUserName(Context context)
Retrieves the current user name.The user name is stored in SharedPreferences.
- Parameters:
context- The context, used to access SharedPreferences.
-
getUserDisplayName
static String getUserDisplayName(Context context)
-
setAppId
static void setAppId(Context context, String appId)
Set App ID.App ID is an unique identifier for each app, issued by S2 platform.The s2_app_id value set in AndroidManifest.xml is applied by default,but if this method is called, the value set here takes precedence.
- Parameters:
context- Application context or ActivityappId- App ID issued by S2 Server
-
setConsentDialogRequired
static void setConsentDialogRequired(Context context, boolean required)
Set whether the consent dialog is required.If set to true and the user has not explicitly agreed with it,the consent dialog will be shown before displaying the offerwall.If set to false, the consent dialog will be skipped.
- Parameters:
context- Activity or Contextrequired- true if the consent dialog is required, false otherwise.
-
isConsentDialogRequired
static boolean isConsentDialogRequired(Context context)
Checks if the consent dialog is required.The consent dialog is required if the user has not explicitly agreed with it.
- Parameters:
context- The context.
-
setConsentAgreed
static void setConsentAgreed(Context context, boolean agreed)
Sets the user's consent status for data collection and personalized advertising.This preference is stored in SharedPreferences.
- Parameters:
context- The context, used to access SharedPreferences.agreed- True if the user agreed to the consent, false otherwise.
-
isConsentAgreed
static boolean isConsentAgreed(Context context)
Checks if the user has agreed to the consent for data collection and personalized advertising.This preference is read from SharedPreferences.
- Parameters:
context- The context, used to access SharedPreferences.
-
isConsentRequired
static boolean isConsentRequired(Context context)
Checks if user consent is required.
Consent is required if the consent dialog is configured to be shown(see setConsentDialogRequired) AND the userhas not yet agreed to the consent (see isConsentAgreed).
- Parameters:
context- The context, used to access SharedPreferences.
-
closeTop
static void closeTop()
Closes the top-most activity in the activity stack managed by the SDK.This is typically used to programmatically close an offerwall activityor any other activity presented by the SDK.
This method relies on an internal
{@code ActivityManager}to keep trackof and close activities. It should be used when you need to dismissthe SDK's UI components from outside the SDK's own UI controls (e.g.,in response to an external event or a custom button in your app).
-
closeAll
static void closeAll()
Closes all activities managed by the S2 Offerwall SDK.This method is typically used to ensure that all SDK-related activitiesare properly closed, for example, when the host application is exitingor when a specific user flow requires all offerwall activities to be dismissed.
-
startActivity
static void startActivity(Activity activity, String placementName)
Start a S2OfferwallActivity with isPoppupStyle is false.
- Parameters:
activity- Activity or ContextplacementName- name of a placement to be displayed in the offerwall.
-
startActivity
static void startActivity(Activity activity, String placementName, boolean isPopupStyle)
Start a S2OfferwallActivity.
- Parameters:
activity- Activity or ContextplacementName- name of a placement to be displayed in the offerwall.isPopupStyle- if true, activity appears from bottom, otherwise the activity appears from right to left.
-
openAdItem
static void openAdItem(Activity activity, long advId, boolean needDetail, String placementFrom)
-
isInitialized
static boolean isInitialized()
-
initSdk
static void initSdk(Context context, S2Offerwall.InitializeListener listener)
-
showConsentDialog
static void showConsentDialog(Activity activity, int resIdDialogLayout, int resIdButtonAgree, int resIdButtonDeny, Runnable onAgree)
-
showConsentDialog
static void showConsentDialog(Activity activity, Runnable onAgree, Runnable onDeny)
-
showConsentDialog
static void showConsentDialog(Activity activity, Runnable onAgree)
-
showConsentDialog
static void showConsentDialog(Activity activity, int resIdDialogLayout, int resIdButtonAgree, int resIdButtonDeny, Runnable onAgree, Runnable onDeny)
-
-
-
-