You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above statement will bring in the entire OneSignalSDK and is the desired state for most integrations. For greater flexibility you can alternatively specify individual modules that make up the full SDK. The possible modules are:
44
46
45
-
`com.onesignal:core`: The required core module provided by the OneSignal SDK, this must be included.
46
-
`com.onesignal:notifications:` Include to bring in notification based functionality.
47
-
`com.onesignal:in-app-messages`: Include to bring in in app message functionality.
48
-
`com.onesignal:location`: Include to bring in location-based functionality.
47
+
-`com.onesignal:core`: The required core module provided by the OneSignal SDK, this must be included.
48
+
-`com.onesignal:notifications`: Include to bring in notification based functionality.
49
+
-`com.onesignal:in-app-messages`: Include to bring in in app message functionality.
50
+
-`com.onesignal:location`: Include to bring in location-based functionality.
49
51
50
52
51
53
## Code Modularization
@@ -71,8 +73,9 @@ In your `ApplicationClass`, initialize OneSignal with the provided methods.
71
73
72
74
Replace `YOUR_APP_ID` with your OneSignal App ID found **Settings > [Keys & IDs](https://documentation.onesignal.com/docs/keys-and-ids)** in your OneSignal dashboard. If you don't have access to the OneSignal app, ask your [Team Members](https://documentation.onesignal.com/docs/manage-team-members) to invite you.
73
75
74
-
<CodeGroup>
75
-
```java Kotlin
76
+
**Kotlin**
77
+
78
+
```kotlin
76
79
packagecom.your.package.name// Replace with your package name
77
80
78
81
importandroid.app.Application
@@ -101,7 +104,9 @@ class ApplicationClass : Application() {
101
104
102
105
```
103
106
104
-
```java Java
107
+
**Java**
108
+
109
+
```java
105
110
packagecom.your.package.name// Replace with your package name
106
111
107
112
importandroid.app.Application;
@@ -127,15 +132,14 @@ public class ApplicationClass extends Application {
127
132
}
128
133
129
134
```
130
-
</CodeGroup>
131
135
132
136
If your integration is not user-centric, there is no additional startup code required. A user is automatically created as part of the push subscription creation, both of which are only accessible from the current device and the OneSignal dashboard.
133
137
134
-
If your integration is user-centric, or you want the ability to identify as the same user on multiple devices, the OneSignal SDK should be called once the user has been identified: [`OneSignal.login("USER_EXTERNAL_ID");`](https://documentation.onesignal.com/docs/mobile-sdk-reference#login-external-id)
138
+
If your integration is user-centric, or you want the ability to identify as the same user on multiple devices, the OneSignal SDK should be called once the user has been identified: [`OneSignal.login("USER_EXTERNAL_ID")`](https://documentation.onesignal.com/docs/mobile-sdk-reference#login-external-id)
135
139
136
140
The `login` method will associate the device’s push subscription to the user that can be identified via alias `external_id`. If a user with the provided `external_id` does not exist, one will be created. If a user does already exist, the user will be updated to include the current device’s push subscription. Note that a device's push subscription will always be transferred to the currently logged in user, as they represent the current owners of that push subscription.
137
141
138
-
Once (or if) the user is no longer identifiable in your app (i.e. they logged out), the OneSignal SDK should be called: [`OneSignal.logout();`](https://documentation.onesignal.com/docs/mobile-sdk-reference#logout)
142
+
Once (or if) the user is no longer identifiable in your app (i.e. they logged out), the OneSignal SDK should be called: [`OneSignal.logout()`](https://documentation.onesignal.com/docs/mobile-sdk-reference#logout)
139
143
140
144
Logging out has the affect of reverting to a “device-scoped” user, which is the new owner of the device’s push subscription.
141
145
@@ -145,20 +149,22 @@ Logging out has the affect of reverting to a “device-scoped” user, which is
145
149
In previous versions of the SDK there was a player that could have zero or one email address, and zero or one phone number for SMS. In the user-centered model there is a user with the current device’s **Push Subscription** along with the ability to have zero or **more** email subscriptions and zero or **more** SMS subscriptions. A user can also have zero or more push subscriptions, one push subscription for each device the user is logged into via the OneSignal SDK.
146
150
147
151
**Push Subscription**
152
+
148
153
The current device’s push subscription can be retrieved via: [`OneSignal.User.pushSubscription`](https://documentation.onesignal.com/docs/mobile-sdk-reference#user-pushsubscription-id)
149
154
150
155
151
-
If at any point you want the user to stop receiving push notifications on the current device (regardless of Android permission status) you can use the push subscription to opt out: [`OneSignal.User.pushSubscription.optOut();`](https://documentation.onesignal.com/docs/mobile-sdk-reference#optout-%2C-optin-%2C-optedin)
156
+
If at any point you want the user to stop receiving push notifications on the current device (regardless of Android permission status) you can use the push subscription to opt out: [`OneSignal.User.pushSubscription.optOut()`](https://documentation.onesignal.com/docs/mobile-sdk-reference#optout-%2C-optin-%2C-optedin)
152
157
153
158
154
-
To resume receiving of push notifications (driving the native permission prompt if OS permissions are not available), you can opt back in: [`OneSignal.User.pushSubscription.optIn();`](https://documentation.onesignal.com/docs/mobile-sdk-reference#optout-%2C-optin-%2C-optedin)
159
+
To resume receiving of push notifications (driving the native permission prompt if OS permissions are not available), you can opt back in: [`OneSignal.User.pushSubscription.optIn()`](https://documentation.onesignal.com/docs/mobile-sdk-reference#optout-%2C-optin-%2C-optedin)
155
160
156
161
157
-
To observe changes to the push subscription a class can implement the IPushSubscriptionObserver interface, and can then be added as an observer: [`OneSignal.User.pushSubscription.addObserver(observer);`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addobserver-push-subscription-changes)
162
+
To observe changes to the push subscription a class can implement the IPushSubscriptionObserver interface, and can then be added as an observer: [`OneSignal.User.pushSubscription.addObserver(observer)`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addobserver-push-subscription-changes)
158
163
159
164
160
165
**Email/SMS Subscriptions**
161
-
Email and/or SMS subscriptions can be added or removed via: [`OneSignal.User.addEmail("customer@company.com");`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addemail-email) or [`OneSignal.User.addSms("+15558675309");`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addsms-sms)
166
+
167
+
Email and/or SMS subscriptions can be added or removed via: [`OneSignal.User.addEmail("customer@company.com")`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addemail-email) or [`OneSignal.User.addSms("+15558675309")`](https://documentation.onesignal.com/docs/mobile-sdk-reference#addsms-sms)
162
168
163
169
164
170
## Kotlin-Related Changes
@@ -167,25 +173,25 @@ The OneSignal SDK has been rewritten in Kotlin. This is typically transparent to
167
173
168
174
In Java this is surfaced on a method via an additional parameter to the method of type `Continuation`. The `Continuation` is a callback mechanism which allows a Java function to gain control when execution has resumed. If this concept is newer to your application codebase, OneSignal provides an optional java helper class to facilitate the callback model. Method `com.onesignal.Continue.none()` can be used to indicate no callback is necessary:
`com.onesignal.Continue.with()` can be used to create a callback lambda expression, which is passed a `ContinueResult` containing information on the success of the underlying coroutine, it's return data, and/or the exception that was thrown:
0 commit comments