-
public interface IUserManagerThe OneSignal user manager is responsible for managing the current user state. When an app starts up for the first time, it is defaulted to having a guest user that is only accessible by the current device. Once the application knows the identity of the user using their app, they should call OneSignal.login providing that identity to OneSignal, at which point all state in here will reflect the state of that known user.
The current user is persisted across the application lifecycle, even when the application is restarted. It is up to the application developer to call OneSignal.login when the user of the application switches, or logs out, to ensure the identity tracked by OneSignal remains in sync.
When you should call OneSignal.login:
When the identity of the user changes (i.e. a login or a context switch)
When the identity of the user is lost (i.e. a logout)
-
-
Method Summary
Modifier and Type Method Description abstract UnitsetLanguage(String value)Set the 2-character language either as a detected language or explicitly set for this user. abstract UnitaddAlias(String label, String id)Set an alias for the current user. abstract UnitaddAliases(Map<String, String> aliases)Add/set aliases for the current user. abstract UnitremoveAlias(String label)Remove an alias from the current user. abstract UnitremoveAliases(Collection<String> labels)Remove multiple aliases from the current user. abstract UnitaddEmail(String email)Add a new email subscription to the current user. abstract UnitremoveEmail(String email)Remove an email subscription from the current user. abstract UnitaddSms(String sms)Add a new SMS subscription to the current user. abstract UnitremoveSms(String sms)Remove an SMS subscription from the current user. abstract UnitaddTag(String key, String value)Add a tag for the current user. abstract UnitaddTags(Map<String, String> tags)Add multiple tags for the current user. abstract UnitremoveTag(String key)Remove the data tag with the provided key from the current user. abstract UnitremoveTags(Collection<String> keys)Remove multiple tags from the current user. abstract Map<String, String>getTags()Return a copy of all local tags from the current user. abstract UnitaddObserver(IUserStateObserver observer)Add an observer to the user state, allowing the provider to be notified whenever the user state has changed. abstract UnitremoveObserver(IUserStateObserver observer)Remove an observer from the user state. abstract IPushSubscriptiongetPushSubscription()The push subscription associated to the current user. abstract StringgetOnesignalId()The UUID generated by OneSignal to represent a user, empty if this is currently unavailable abstract StringgetExternalId()The External ID is OneSignal's default and recommended alias label. -
-
Method Detail
-
setLanguage
abstract Unit setLanguage(String value)
Set the 2-character language either as a detected language or explicitly set for this user. See See Supported Languages | OneSignal
- Parameters:
value- The 2-character language string, or an empty string to use the device default.
-
addAlias
abstract Unit addAlias(String label, String id)
Set an alias for the current user. If this alias already exists it will be overwritten.
- Parameters:
label- The alias label that you want to set against the current user.id- The alias id that should be set against the current user.
-
addAliases
abstract Unit addAliases(Map<String, String> aliases)
Add/set aliases for the current user. If any alias already exists it will be overwritten.
- Parameters:
aliases- A map of the alias label -> alias id that should be set against the user.
-
removeAlias
abstract Unit removeAlias(String label)
Remove an alias from the current user.
- Parameters:
label- The alias label that should no longer be set for the current user.
-
removeAliases
abstract Unit removeAliases(Collection<String> labels)
Remove multiple aliases from the current user.
- Parameters:
labels- The collection of alias labels, all of which will be removed from the current user.
-
addEmail
abstract Unit addEmail(String email)
Add a new email subscription to the current user.
- Parameters:
email- The email address that the current user has subscribed for.
-
removeEmail
abstract Unit removeEmail(String email)
Remove an email subscription from the current user.
- Parameters:
email- The email address that the current user was subscribed for, and should no longer be.
-
addSms
abstract Unit addSms(String sms)
Add a new SMS subscription to the current user.
- Parameters:
sms- The phone number that the current user has subscribed for, in E.164 format.
-
removeSms
abstract Unit removeSms(String sms)
Remove an SMS subscription from the current user.
- Parameters:
sms- The sms address that the current user was subscribed for, and should no longer be.
-
addTag
abstract Unit addTag(String key, String value)
Add a tag for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. See Data Tags | OneSignal.
If the tag key already exists, it will be replaced with the value provided here.
- Parameters:
key- The key of the data tag.value- THe new value of the data tag.
-
addTags
abstract Unit addTags(Map<String, String> tags)
Add multiple tags for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. See Data Tags | OneSignal.
If the tag key already exists, it will be replaced with the value provided here.
- Parameters:
tags- A map of tags, all of which will be added/updated for the current user.
-
removeTag
abstract Unit removeTag(String key)
Remove the data tag with the provided key from the current user.
- Parameters:
key- The key of the data tag.
-
removeTags
abstract Unit removeTags(Collection<String> keys)
Remove multiple tags from the current user.
- Parameters:
keys- The collection of keys, all of which will be removed from the current user.
-
getTags
abstract Map<String, String> getTags()
Return a copy of all local tags from the current user.
-
addObserver
abstract Unit addObserver(IUserStateObserver observer)
Add an observer to the user state, allowing the provider to be notified whenever the user state has changed.
Important: When using the observer to retrieve the onesignalId, check the externalId as well to confirm the values are associated with the expected user.
-
removeObserver
abstract Unit removeObserver(IUserStateObserver observer)
Remove an observer from the user state.
-
getPushSubscription
abstract IPushSubscription getPushSubscription()
The push subscription associated to the current user.
-
getOnesignalId
abstract String getOnesignalId()
The UUID generated by OneSignal to represent a user, empty if this is currently unavailable
-
getExternalId
abstract String getExternalId()
The External ID is OneSignal's default and recommended alias label. This should be the main identifier you use to identify users. It is set when calling the OneSignal.login method.
This is empty if the External ID has not been set.
-
-
-
-