Skip to content

Commit 4048f31

Browse files
1) OneSignal push notification feature implemented for user.
2) Now user can send push notification from FCM or OneSignal. 3) Crashes is fixed 4) And Now We are releasing sdk version 2.2.0.
1 parent 749f8bf commit 4048f31

File tree

11 files changed

+248
-215
lines changed

11 files changed

+248
-215
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
> # Note
44
> WittyFeed SDK API is now `OneFeed Android SDK`,
5-
> New v2.1.15 made live on 07 Sep' 2018
5+
> New v2.2.0 made live on 21 Sep' 2018
66
77
[![Platform](https://img.shields.io/badge/Platform-Android-green.svg)](#)
8-
[![Source](https://img.shields.io/badge/Source-JitPack-brightgreen.svg)](https://jitpack.io/private#vatsanatech/OneFeed-Android-SDK/2.1.15)
8+
[![Source](https://img.shields.io/badge/Source-JitPack-brightgreen.svg)](https://jitpack.io/private#vatsanatech/OneFeed-Android-SDK/2.2.0)
99
[![License](https://img.shields.io/badge/LICENSE-WittyFeed%20SDK%20License-blue.svg)](https://github.com/vatsanatech/OneFeed-Android-SDK/blob/master/LICENSE)
1010

1111
## Table Of Contents
@@ -34,7 +34,7 @@ Browse through the example app in this repository to see how the OneFeed SDK can
3434

3535
### 1.2. Incorporating the SDK
3636

37-
1. [Integrate OneFeed with JitPack](https://jitpack.io/private#vatsanatech/OneFeed-Android-SDK/2.1.15)
37+
1. [Integrate OneFeed with JitPack](https://jitpack.io/private#vatsanatech/OneFeed-Android-SDK/2.2.0)
3838

3939
2. SignUp at [OneFeed](http://www.onefeed.ai/) and create a new application to integrate with
4040

@@ -51,10 +51,10 @@ Browse through the example app in this repository to see how the OneFeed SDK can
5151
}
5252
}
5353
```
54-
* add OneFeed-Android-SDK:2.1.15 in your app level build.gradle
54+
* add OneFeed-Android-SDK:2.2.0 in your app level build.gradle
5555
```gradle
5656
dependencies {
57-
compile 'com.github.vatsanatech:OneFeed-Android-SDK:2.1.15'
57+
compile 'com.github.vatsanatech:OneFeed-Android-SDK:2.2.0'
5858
}
5959
```
6060

app/google-services.json

+7-38
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,27 @@
11
{
22
"project_info": {
3-
"project_number": "374106365444",
4-
"firebase_url": "https://witty-android-sdk.firebaseio.com",
5-
"project_id": "witty-android-sdk",
6-
"storage_bucket": "witty-android-sdk.appspot.com"
3+
"project_number": "894695272295",
4+
"firebase_url": "https://onefeed-sdk-v1.firebaseio.com",
5+
"project_id": "onefeed-sdk-v1",
6+
"storage_bucket": "onefeed-sdk-v1.appspot.com"
77
},
88
"client": [
99
{
1010
"client_info": {
11-
"mobilesdk_app_id": "1:374106365444:android:9c891c0c2080995d",
12-
"android_client_info": {
13-
"package_name": "com.sdk.wittyfeed.debug"
14-
}
15-
},
16-
"oauth_client": [
17-
{
18-
"client_id": "374106365444-iu4e3uqon026oesm7219o9sids4kvpmh.apps.googleusercontent.com",
19-
"client_type": 3
20-
}
21-
],
22-
"api_key": [
23-
{
24-
"current_key": "AIzaSyDAmVMELCKaB2ld0yRRNhjpkWtL1xTigkg"
25-
}
26-
],
27-
"services": {
28-
"analytics_service": {
29-
"status": 1
30-
},
31-
"appinvite_service": {
32-
"status": 1,
33-
"other_platform_oauth_client": []
34-
},
35-
"ads_service": {
36-
"status": 2
37-
}
38-
}
39-
},
40-
{
41-
"client_info": {
42-
"mobilesdk_app_id": "1:374106365444:android:b29e8182efb73ccb",
11+
"mobilesdk_app_id": "1:894695272295:android:b29e8182efb73ccb",
4312
"android_client_info": {
4413
"package_name": "com.sdk.wittyfeed.demo"
4514
}
4615
},
4716
"oauth_client": [
4817
{
49-
"client_id": "374106365444-iu4e3uqon026oesm7219o9sids4kvpmh.apps.googleusercontent.com",
18+
"client_id": "894695272295-3gam46iue8bfkga602emn237dv8r0s7d.apps.googleusercontent.com",
5019
"client_type": 3
5120
}
5221
],
5322
"api_key": [
5423
{
55-
"current_key": "AIzaSyDAmVMELCKaB2ld0yRRNhjpkWtL1xTigkg"
24+
"current_key": "AIzaSyCdBSwFDX589j9Z_mfkRmutaEi92XtOzmc"
5625
}
5726
],
5827
"services": {

app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
<!-- Disable opening of launcher Activity -->
6868
<meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
6969

70-
<service
70+
<!--<service
7171
android:name=".NotificationExtenderExample"
7272
android:permission="android.permission.BIND_JOB_SERVICE"
7373
android:exported="false">
7474
<intent-filter>
7575
<action android:name="com.onesignal.NotificationExtender" />
7676
</intent-filter>
77-
</service>
77+
</service>-->
7878

7979
</application>
8080

app/src/main/java/com/wittyfeed/sdk/demo/MainActivity.java

+60-23
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
import com.wittyfeed.sdk.onefeed.Utils.OneFeedBuilder;
2222

2323

24+
import org.json.JSONException;
25+
import org.json.JSONObject;
26+
2427
import java.util.HashMap;
2528

2629
public class MainActivity extends AppCompatActivity {
@@ -40,20 +43,8 @@ protected void onCreate(Bundle savedInstanceState) {
4043
setContentView(R.layout.activity_main);
4144

4245
activity = this;
43-
FCM_TOKEN = FirebaseInstanceId.getInstance().getToken();
4446
viewPager = findViewById(R.id.viewPager);
4547

46-
if (FCM_TOKEN == null) {
47-
FCM_TOKEN = "";
48-
}
49-
50-
51-
String topicName = "OneFeed_" + APP_ID + "_" + Constant.ONE_FEED_VERSION;
52-
53-
FirebaseMessaging.getInstance().subscribeToTopic(topicName);
54-
55-
//System.out.println("FCM Token: " + FCM_TOKEN);
56-
5748

5849
// ====================
5950
// SDK WORK STARTS HERE
@@ -134,24 +125,70 @@ public void onError() {
134125
* below code is ***required*** for Initializing WittyFeed Android SDK API,
135126
*/
136127
OneFeedMain.setHideBackButtonFromMainFeed(false);
137-
OneFeedMain.getInstance().init(getBaseContext(), APP_ID, API_KEY, FCM_TOKEN);
138128

139-
/*
140-
* Below code is ***required*** for consistent unsubscription and token update on sdk version change
141-
*/
142-
if(!(OneFeedMain.getInstance().ofSharedPreference.getSDKVersion().equals(""))){
143-
if(!OneFeedMain.getInstance().ofSharedPreference.getSDKVersion().equals(Constant.ONE_FEED_VERSION)){
144-
OneFeedMain.getInstance().fcmTokenManager.updateTokenForVersionChange();
145-
String oldTopic = "OneFeed_" + APP_ID + "_" + OneFeedMain.getInstance().ofSharedPreference.getSDKVersion();
146-
FirebaseMessaging.getInstance().unsubscribeFromTopic(oldTopic);
129+
if(Root.notificationProvider.equalsIgnoreCase("F")){
130+
FCM_TOKEN = FirebaseInstanceId.getInstance().getToken();
131+
if (FCM_TOKEN == null) {
132+
FCM_TOKEN = "";
147133
}
134+
Log.e("FCM Token:", FCM_TOKEN);
135+
136+
String topicName = "OneFeed_" + APP_ID + "_" + Constant.ONE_FEED_VERSION;
137+
FirebaseMessaging.getInstance().subscribeToTopic(topicName);
138+
139+
OneFeedMain.getInstance().init(getBaseContext(), APP_ID, API_KEY, FCM_TOKEN);
140+
141+
/*
142+
* Below code is ***required*** for consistent unsubscription and token update on sdk version change
143+
*/
144+
if (!(OneFeedMain.getInstance().ofSharedPreference.getSDKVersion().equals(""))) {
145+
if (!OneFeedMain.getInstance().ofSharedPreference.getSDKVersion().equals(Constant.ONE_FEED_VERSION)) {
146+
OneFeedMain.getInstance().fcmTokenManager.updateTokenForVersionChange();
147+
String oldTopic = "OneFeed_" + APP_ID + "_" + OneFeedMain.getInstance().ofSharedPreference.getSDKVersion();
148+
FirebaseMessaging.getInstance().unsubscribeFromTopic(oldTopic);
149+
}
150+
}
151+
OneFeedMain.getInstance().ofSharedPreference.setSDKVersion(Constant.ONE_FEED_VERSION);
152+
}else{
153+
154+
OneSignal.getTags(new OneSignal.GetTagsHandler() {
155+
@Override
156+
public void tagsAvailable(JSONObject tags) {
157+
if (tags != null) {
158+
try {
159+
String tag = tags.getString("onefeed");
160+
if (!tag.equalsIgnoreCase("app_id_" + Constant.ONE_FEED_VERSION)) {
161+
OneSignal.sendTag("onefeed", "app_id_" + Constant.ONE_FEED_VERSION);
162+
}
163+
} catch (JSONException e) {
164+
e.printStackTrace();
165+
}
166+
}else{
167+
OneSignal.sendTag("onefeed", "app_id_" + Constant.ONE_FEED_VERSION);
168+
}
169+
}
170+
});
171+
172+
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
173+
@Override
174+
public void idsAvailable(String userId, String registrationId) {
175+
Log.e("debug", "User:" + userId);
176+
OneFeedMain.getInstance().init(getBaseContext(), APP_ID, API_KEY, userId);
177+
178+
179+
if (registrationId != null)
180+
Log.e("debug", "registrationId:" + registrationId);
181+
182+
}
183+
});
148184
}
149-
OneFeedMain.getInstance().ofSharedPreference.setSDKVersion(Constant.ONE_FEED_VERSION);
185+
186+
150187

151188
/*
152189
* Set Intent of the Activity you want to open on Back press from Story opens from Notification
153190
*/
154-
OFNotificationManager.getInstance().setHomeScreenIntent(this, new Intent(this.getApplicationContext(),MainActivity.class));
191+
OFNotificationManager.getInstance().setHomeScreenIntent(this, new Intent(this.getApplicationContext(), MainActivity.class));
155192

156193

157194
// ==================

app/src/main/java/com/wittyfeed/sdk/demo/NotificationExtenderExample.java

-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
3131
};
3232

3333
OSNotificationDisplayedResult displayedResult = displayNotification(overrideSettings);
34-
try {
35-
Log.d("OneSignalExample", "Notification displayed with id: " +
36-
notification.payload.additionalData.getJSONObject("custom").getJSONObject("a").get("H"));
37-
} catch (JSONException e) {
38-
e.printStackTrace();
39-
}
4034

4135
// Return true to stop the notification from displaying
4236
return true;

app/src/main/java/com/wittyfeed/sdk/demo/Root.java

+23-27
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.wittyfeed.sdk.demo;
22

33
import android.app.Application;
4+
import android.text.TextUtils;
45
import android.util.Log;
56

67
import com.onesignal.OSNotification;
78
import com.onesignal.OneSignal;
9+
import com.wittyfeed.sdk.onefeed.OFNotificationManager;
10+
11+
import org.w3c.dom.Text;
812

9-
import org.json.JSONObject;
1013

1114
/**
1215
* Created by Yogesh Soni.
@@ -16,43 +19,36 @@
1619
*/
1720
public class Root extends Application {
1821

22+
public static final String notificationProvider = "E";
23+
1924
@Override
2025
public void onCreate() {
2126
super.onCreate();
2227
// OneSignal Initialization
23-
OneSignal.startInit(this)
24-
.setNotificationReceivedHandler(new ExampleNotificationReceivedHandler())
25-
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
26-
.unsubscribeWhenNotificationsAreDisabled(true)
27-
.init();
28+
if(notificationProvider.equalsIgnoreCase("E")) {
29+
OneSignal.startInit(this)
30+
.setNotificationReceivedHandler(new ExampleNotificationReceivedHandler())
31+
.inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
32+
.unsubscribeWhenNotificationsAreDisabled(true)
33+
.init();
34+
}
2835
}
2936

3037
private class ExampleNotificationReceivedHandler implements OneSignal.NotificationReceivedHandler {
3138
@Override
3239
public void notificationReceived(OSNotification notification) {
33-
JSONObject data = notification.payload.additionalData;
3440
String notificationID = notification.payload.notificationID;
35-
String title = notification.payload.title;
36-
String body = notification.payload.body;
37-
String smallIcon = notification.payload.smallIcon;
38-
String largeIcon = notification.payload.largeIcon;
39-
String bigPicture = notification.payload.bigPicture;
40-
String smallIconAccentColor = notification.payload.smallIconAccentColor;
41-
String sound = notification.payload.sound;
42-
String ledColor = notification.payload.ledColor;
43-
int lockScreenVisibility = notification.payload.lockScreenVisibility;
44-
String groupKey = notification.payload.groupKey;
45-
String groupMessage = notification.payload.groupMessage;
46-
String fromProjectNumber = notification.payload.fromProjectNumber;
47-
String rawPayload = notification.payload.rawPayload;
48-
49-
String customKey;
50-
Log.i("OneSignalExample", "NotificationID received: " + notificationID);
5141

52-
if (data != null) {
53-
customKey = data.optString("customkey", null);
54-
if (customKey != null)
55-
Log.i("OneSignalExample", "customkey set with value: " + customKey);
42+
Log.i("OneSignalExample", "NotificationID received: " + notificationID);
43+
String agent = notification.payload.additionalData.optString("notiff_agent", null);
44+
45+
if(!TextUtils.isEmpty(agent) && agent.equalsIgnoreCase("wittyfeed_sdk")) {
46+
OFNotificationManager
47+
.getInstance()
48+
.handleOneSignalNotification(Root.this, "",
49+
notification.payload.additionalData, R.mipmap.ic_launcher, "108");
50+
}else {
51+
// Handle by user
5652
}
5753
}
5854
}

0 commit comments

Comments
 (0)