-
public class OneSignalThis singleton class is the entry point to the OneSignal SDK. It is designed to make OneSignal easy to use.
No instance management is required from the app developer.
This is a wrapper around an instance of IOneSignal, no logic lives in this class.
Note: This does not implement IOneSignal itself because you cannot specify @JvmStatic on an override function. The cleanliness that @JvmStatic gives when calling from java outweighs the use of an interface. This class however should implement IOneSignal "in spirit".
-
-
Field Summary
Fields Modifier and Type Field Description private final static BooleanisInitializedprivate final static StringsdkVersionprivate final static IUserManagerUserprivate final static ISessionManagerSessionprivate final static INotificationsManagerNotificationsprivate final static ILocationManagerLocationprivate final static IInAppMessagesManagerInAppMessagesprivate final static IDebugManagerDebugprivate static BooleanconsentRequiredprivate static BooleanconsentGivenprivate static BooleandisableGMSMissingPromptprivate final IServiceProviderservicespublic final static OneSignalINSTANCE
-
Method Summary
Modifier and Type Method Description final static UnitinitWithContext(Context context, String appId)Initialize the OneSignal SDK. final static BooleaninitWithContext(Context context)Used to initialize the SDK when driven through user action. final static Unitlogin(String externalId)Login to OneSignal under the user identified by the externalId provided. final static Unitlogin(String externalId, String jwtBearerToken)Login to OneSignal under the user identified by the externalId provided. final static Unitlogout()Logout the user previously logged in via login. final <T extends Any> TgetService()Inline function to retrieve a specific service. final <T extends Any> TgetServiceOrNull()Inline function to retrieve a specific service, or null if that service does not exist. final static BooleangetIsInitialized()final static StringgetSdkVersion()final static IUserManagergetUser()final static ISessionManagergetSession()final static INotificationsManagergetNotifications()final static ILocationManagergetLocation()final static IInAppMessagesManagergetInAppMessages()final static IDebugManagergetDebug()final static BooleangetConsentRequired()final static UnitsetConsentRequired(Boolean consentRequired)final static BooleangetConsentGiven()final static UnitsetConsentGiven(Boolean consentGiven)final static BooleangetDisableGMSMissingPrompt()final static UnitsetDisableGMSMissingPrompt(Boolean disableGMSMissingPrompt)final IServiceProvidergetServices()-
-
Method Detail
-
initWithContext
final static Unit initWithContext(Context context, String appId)
Initialize the OneSignal SDK. This should be called during startup of the application.
- Parameters:
context- The Android context the SDK should use.appId- The application ID the OneSignal SDK is bound to.
-
initWithContext
final static Boolean initWithContext(Context context)
Used to initialize the SDK when driven through user action. It is assumed initWithContext has been called by the app developer, providing the appId, which has been cached for this purpose.
THIS IS AN INTERNAL INTERFACE AND SHOULD NOT BE USED DIRECTLY.
-
login
final static Unit login(String externalId)
Login to OneSignal under the user identified by the externalId provided. The act of logging a user into the OneSignal SDK will switch the User context to that specific user.
If the externalId exists the user will be retrieved and the context set from that user information. If operations have already been performed under a guest user, they will not be applied to the now logged in user (they will be lost).
If the externalId does not exist the user will be created and the context set from the current local state. If operations have already been performed under a guest user those operations will be applied to the newly created user.
Push Notifications and In App Messaging Logging in a new user will automatically transfer push notification and in app messaging subscriptions from the current user (if there is one) to the newly logged in user. This is because both Push and IAM are owned by the device.
- Parameters:
externalId- The external ID of the user that is to be logged in.
-
login
final static Unit login(String externalId, String jwtBearerToken)
Login to OneSignal under the user identified by the externalId provided. The act of logging a user into the OneSignal SDK will switch the User context to that specific user.
If the externalId exists the user will be retrieved and the context set from that user information. If operations have already been performed under a guest user, they will not be applied to the now logged in user (they will be lost).
If the externalId does not exist the user will be created and the context set from the current local state. If operations have already been performed under a guest user those operations will be applied to the newly created user.
Push Notifications and In App Messaging Logging in a new user will automatically transfer push notification and in app messaging subscriptions from the current user (if there is one) to the newly logged in user. This is because both Push and IAM are owned by the device.
- Parameters:
externalId- The external ID of the user that is to be logged in.jwtBearerToken- The optional JWT bearer token generated by your backend to establish trust for the login operation.
-
getService
final <T extends Any> T getService()
Inline function to retrieve a specific service.
THIS IS AN INTERNAL INTERFACE AND SHOULD NOT BE USED DIRECTLY.
-
getServiceOrNull
final <T extends Any> T getServiceOrNull()
Inline function to retrieve a specific service, or null if that service does not exist.
THIS IS AN INTERNAL INTERFACE AND SHOULD NOT BE USED DIRECTLY.
-
getIsInitialized
final static Boolean getIsInitialized()
-
getSdkVersion
final static String getSdkVersion()
-
getUser
final static IUserManager getUser()
-
getSession
final static ISessionManager getSession()
-
getNotifications
final static INotificationsManager getNotifications()
-
getLocation
final static ILocationManager getLocation()
-
getInAppMessages
final static IInAppMessagesManager getInAppMessages()
-
getDebug
final static IDebugManager getDebug()
-
getConsentRequired
final static Boolean getConsentRequired()
-
setConsentRequired
final static Unit setConsentRequired(Boolean consentRequired)
-
getConsentGiven
final static Boolean getConsentGiven()
-
setConsentGiven
final static Unit setConsentGiven(Boolean consentGiven)
-
getDisableGMSMissingPrompt
final static Boolean getDisableGMSMissingPrompt()
-
setDisableGMSMissingPrompt
final static Unit setDisableGMSMissingPrompt(Boolean disableGMSMissingPrompt)
-
getServices
final IServiceProvider getServices()
-
-
-
-