Skip to content

Commit 8cb3065

Browse files
Update README.md
1 parent 4048f31 commit 8cb3065

File tree

1 file changed

+92
-38
lines changed

1 file changed

+92
-38
lines changed

README.md

+92-38
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,13 @@ Browse through the example app in this repository to see how the OneFeed SDK can
5858
}
5959
```
6060

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-
7761
> ## Notice
7862
> We encourage developers to always check for latest SDK version and refer to its updated documentation to use it.
7963
80-
### 1.3. Initializing the SDK
64+
### 1.3 Initializing the SDK
8165

8266
```java
8367

84-
//For Notifications
85-
86-
String topicName = "OneFeed_" + APP_ID + "_" + Constant.ONE_FEED_VERSION;
87-
FirebaseMessaging.getInstance().subscribeToTopic(topicName);
88-
8968
// OPTIONAL to provide basic user_meta.
9069
// By providing basic user_meta your app can receive targeted content which has an higher CPM then regular content.
9170
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
9776
// user Interests. String with a max_length = 100
9877
// SAMPLE CODE BELOW, DO ADD YOUR OWN CATEOGORIES OF INTERESTS
9978
// 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
10180

10281
// Passing 'mUserMeta' IS OPTIONAL
10382
ApiClient.getInstance().appendCustomUserMetaToUserMeta(mUserMeta);
@@ -121,19 +100,63 @@ Browse through the example app in this repository to see how the OneFeed SDK can
121100

122101
OneFeedMain.setHideBackButtonFromMainFeed(true);
123102

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+
124113
// initializing SDK here (mandatory)
125114
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+
}
136126
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+
});
137160

138161
// OPTIONAL: Set Intent of the Activity you want to open on Back press from Story that opens from Notification
139162
OFNotificationManager.getInstance().setHomeScreenIntent(this, new Intent(this.getApplicationContext(),MainActivity.class));
@@ -222,20 +245,17 @@ Step 4:
222245

223246
```
224247

225-
### 1.7. For Notifications Service of OneFeed
248+
### 1.7.1 For FCM Notifications Service of OneFeed
226249

227250
In your class which extends FirebaseInstanceIDService, update with the code below
228251
```java
229252
@Override
230253
public void onTokenRefresh() {
231254
// Get updated InstanceID token.
232255
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
233-
Log.d("FCM_CUSTOM", "Refreshed token:- " + refreshedToken);
234256

235-
//
236-
// * Mandatory for Using Notification Service by OneFeed*
257+
// * Mandatory for Using Notification Service by OneFeed*
237258
// To notify OneFeed SDK about your updated fcm_token
238-
//
239259
if(OneFeedMain.getInstance().getFcmTokenManager()!=null)
240260
OneFeedMain.getInstance().getFcmTokenManager().refreshToken(refreshedToken);
241261
}
@@ -270,6 +290,40 @@ In your class which extends FirebaseMessagingService, update with the code below
270290
);
271291
}
272292
```
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+
```
273327

274328
### 1.8. OneFeed is built for Portrait
275329
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

Comments
 (0)