@@ -58,34 +58,13 @@ Browse through the example app in this repository to see how the OneFeed SDK can
58
58
}
59
59
```
60
60
61
- 4 . Add the following library dependency to your project
62
-
63
- ``` gradle
64
- compile 'com.android.support:appcompat-v7:27.1.0'
65
- compile 'com.android.support:support-v4:27.1.0'
66
- compile 'com.android.support:design:27.1.0'
67
- compile 'com.android.support:cardview-v7:27.1.0'
68
- compile 'com.android.support:recyclerview-v7:27.1.0'
69
-
70
- compile 'com.github.bumptech.glide:glide:4.3.1'
71
- annotationProcessor 'com.github.bumptech.glide:compiler:4.3.1'
72
- compile 'com.google.code.gson:gson:2.8.2'
73
- compile 'com.android.volley:volley:1.0.0'
74
- compile 'com.android.support:customtabs:27.1.0'
75
- ```
76
-
77
61
> ## Notice
78
62
> We encourage developers to always check for latest SDK version and refer to its updated documentation to use it.
79
63
80
- ### 1.3. Initializing the SDK
64
+ ### 1.3 Initializing the SDK
81
65
82
66
``` java
83
67
84
- // For Notifications
85
-
86
- String topicName = " OneFeed_" + APP_ID + " _" + Constant . ONE_FEED_VERSION ;
87
- FirebaseMessaging . getInstance(). subscribeToTopic(topicName);
88
-
89
68
// OPTIONAL to provide basic user_meta.
90
69
// By providing basic user_meta your app can receive targeted content which has an higher CPM then regular content.
91
70
HashMap<String , String > mUserMeta = new HashMap<> ();
@@ -97,7 +76,7 @@ Browse through the example app in this repository to see how the OneFeed SDK can
97
76
// user Interests. String with a max_length = 100
98
77
// SAMPLE CODE BELOW, DO ADD YOUR OWN CATEOGORIES OF INTERESTS
99
78
// OPTIONAL
100
- mUserMeta. put(" client_interests" , " love, funny, sad, politics, food, technology, DIY, friendship, hollywood, bollywood, NSFW" ); // string max_length = 100
79
+ mUserMeta. put(" client_interests" , " love, funny, sad, politics, food, technology, DIY, friendship, hollywood, bollywood, NSFW" ); // string max_length = 100
101
80
102
81
// Passing 'mUserMeta' IS OPTIONAL
103
82
ApiClient . getInstance(). appendCustomUserMetaToUserMeta(mUserMeta);
@@ -121,19 +100,63 @@ Browse through the example app in this repository to see how the OneFeed SDK can
121
100
122
101
OneFeedMain . setHideBackButtonFromMainFeed(true );
123
102
103
+ // If user use FCM for sending push notification. Follow below code
104
+ FCM_TOKEN = FirebaseInstanceId . getInstance(). getToken();
105
+ if (FCM_TOKEN == null ) {
106
+ FCM_TOKEN = " " ;
107
+ }
108
+ Log . e(" FCM Token:" , FCM_TOKEN );
109
+
110
+ String topicName = " OneFeed_" + APP_ID + " _" + Constant . ONE_FEED_VERSION ;
111
+ FirebaseMessaging . getInstance(). subscribeToTopic(topicName);
112
+
124
113
// initializing SDK here (mandatory)
125
114
OneFeedMain . getInstance(). init(getBaseContext(), APP_ID , API_KEY , FCM_TOKEN );
126
-
127
- // Below code is required for consistent unsubscription from FCM topics and token update on onefeed sdk version change
128
-
129
- if (! (OneFeedMain . getInstance(). ofSharedPreference. getSDKVersion(). equals(" " ))){
130
- if (! OneFeedMain . getInstance(). ofSharedPreference. getSDKVersion(). equals(Constant . ONE_FEED_VERSION )){
131
- OneFeedMain . getInstance(). fcmTokenManager. updateTokenForVersionChange();
132
- String oldTopic = " OneFeed_" + APP_ID + " _" + OneFeedMain . getInstance(). ofSharedPreference. getSDKVersion();
133
- FirebaseMessaging . getInstance(). unsubscribeFromTopic(oldTopic);
134
- }
135
- }
115
+
116
+ /*
117
+ * Below code is ***required*** for consistent unsubscription and token update on sdk version change
118
+ */
119
+ if (! (OneFeedMain . getInstance(). ofSharedPreference. getSDKVersion(). equals(" " ))) {
120
+ if (! OneFeedMain . getInstance(). ofSharedPreference. getSDKVersion(). equals(Constant . ONE_FEED_VERSION )) {
121
+ OneFeedMain . getInstance(). fcmTokenManager. updateTokenForVersionChange();
122
+ String oldTopic = " OneFeed_" + APP_ID + " _" + OneFeedMain . getInstance(). ofSharedPreference. getSDKVersion();
123
+ FirebaseMessaging . getInstance(). unsubscribeFromTopic(oldTopic);
124
+ }
125
+ }
136
126
OneFeedMain . getInstance(). ofSharedPreference. setSDKVersion(Constant . ONE_FEED_VERSION );
127
+
128
+ // If user use OneSignal for sending push notification. Follow below code
129
+ OneSignal . getTags(new OneSignal .GetTagsHandler () {
130
+ @Override
131
+ public void tagsAvailable (JSONObject tags ) {
132
+ if (tags != null ) {
133
+ try {
134
+ String tag = tags. getString(" onefeed" );
135
+ if (! tag. equalsIgnoreCase(" app_id_" + Constant . ONE_FEED_VERSION )) {
136
+ OneSignal . sendTag(" onefeed" , " app_id_" + Constant . ONE_FEED_VERSION );
137
+ }
138
+ } catch (JSONException e) {
139
+ e. printStackTrace();
140
+ }
141
+ }else {
142
+ OneSignal . sendTag(" onefeed" , " app_id_" + Constant . ONE_FEED_VERSION );
143
+ }
144
+ }
145
+ });
146
+
147
+ OneSignal . idsAvailable(new OneSignal .IdsAvailableHandler () {
148
+ @Override
149
+ public void idsAvailable (String userId , String registrationId ) {
150
+ Log . e(" debug" , " User:" + userId);
151
+
152
+ // initializing SDK here (mandatory)
153
+ OneFeedMain . getInstance(). init(getBaseContext(), APP_ID , API_KEY , userId);
154
+
155
+
156
+ if (registrationId != null )
157
+ Log . e(" debug" , " registrationId:" + registrationId);
158
+ }
159
+ });
137
160
138
161
// OPTIONAL: Set Intent of the Activity you want to open on Back press from Story that opens from Notification
139
162
OFNotificationManager . getInstance(). setHomeScreenIntent(this , new Intent (this . getApplicationContext(),MainActivity . class));
@@ -222,20 +245,17 @@ Step 4:
222
245
223
246
```
224
247
225
- ### 1.7. For Notifications Service of OneFeed
248
+ ### 1.7.1 For FCM Notifications Service of OneFeed
226
249
227
250
In your class which extends FirebaseInstanceIDService, update with the code below
228
251
``` java
229
252
@Override
230
253
public void onTokenRefresh() {
231
254
// Get updated InstanceID token.
232
255
String refreshedToken = FirebaseInstanceId . getInstance(). getToken();
233
- Log . d(" FCM_CUSTOM" , " Refreshed token:- " + refreshedToken);
234
256
235
- //
236
- // * Mandatory for Using Notification Service by OneFeed*
257
+ // * Mandatory for Using Notification Service by OneFeed*
237
258
// To notify OneFeed SDK about your updated fcm_token
238
- //
239
259
if (OneFeedMain . getInstance(). getFcmTokenManager()!= null )
240
260
OneFeedMain . getInstance(). getFcmTokenManager(). refreshToken(refreshedToken);
241
261
}
@@ -270,6 +290,40 @@ In your class which extends FirebaseMessagingService, update with the code below
270
290
);
271
291
}
272
292
```
293
+ ### 1.7.2 For OneSignal Notifications Service of OneFeed
294
+
295
+ In your class which extends Application, update with the code below
296
+ ``` java
297
+ @Override
298
+ public void onCreate() {
299
+ super . onCreate();
300
+ OneSignal . startInit(this )
301
+ .setNotificationReceivedHandler(new ExampleNotificationReceivedHandler ())
302
+ .inFocusDisplaying(OneSignal . OSInFocusDisplayOption . Notification )
303
+ .unsubscribeWhenNotificationsAreDisabled(true )
304
+ .init();
305
+ }
306
+
307
+ private class ExampleNotificationReceivedHandler implements OneSignal .NotificationReceivedHandler {
308
+ @Override
309
+ public void notificationReceived (OSNotification notification ) {
310
+ String notificationID = notification. payload. notificationID;
311
+
312
+ String agent = notification. payload. additionalData. optString(" notiff_agent" , null );
313
+
314
+ // NOTE: optionally you can check that notification has arrived from WittyFeed by below line -
315
+ if (! TextUtils . isEmpty(agent) && agent. equalsIgnoreCase(" wittyfeed_sdk" )) {
316
+ OFNotificationManager
317
+ .getInstance()
318
+ .handleOneSignalNotification(Root . this , " " ,
319
+ notification. payload. additionalData, R . mipmap. ic_launcher, YOUR_APP_ID );
320
+ }else {
321
+ // Handle by user
322
+ }
323
+ }
324
+ }
325
+
326
+ ```
273
327
274
328
### 1.8. OneFeed is built for Portrait
275
329
OneFeed works best in the world's default mode i.e Potrait, So don't forget to add the below line in Manifest.
0 commit comments