Skip to content

Commit 11e7475

Browse files
committed
Added notification stacking feature
* Added notification stacking - When sending a notification set an android group to enable to stack of notification in the same group.
1 parent 7306c12 commit 11e7475

26 files changed

+1441
-509
lines changed

OneSignalSDK/app/app.iml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
<orderEntry type="library" exported="" name="support-annotations-22.1.1" level="project" />
9999
<orderEntry type="library" exported="" scope="TEST" name="asm-tree-5.0.1" level="project" />
100100
<orderEntry type="library" exported="" scope="TEST" name="robolectric-annotations-3.0-rc3" level="project" />
101-
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
102101
<orderEntry type="library" exported="" scope="TEST" name="asm-analysis-5.0.1" level="project" />
102+
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
103103
<orderEntry type="library" exported="" name="appcompat-v7-22.1.1" level="project" />
104104
<orderEntry type="library" exported="" scope="TEST" name="robolectric-utils-3.0-rc3" level="project" />
105105
<orderEntry type="library" exported="" scope="TEST" name="icu4j-53.1" level="project" />
@@ -108,9 +108,10 @@
108108
<orderEntry type="library" exported="" scope="TEST" name="ant-launcher-1.8.0" level="project" />
109109
<orderEntry type="library" exported="" scope="TEST" name="accessibility-test-framework-1.0" level="project" />
110110
<orderEntry type="library" exported="" scope="TEST" name="bcprov-jdk16-1.46" level="project" />
111+
<orderEntry type="library" exported="" scope="TEST" name="shadows-support-v4-3.0-rc3" level="project" />
111112
<orderEntry type="library" exported="" scope="TEST" name="asm-util-5.0.1" level="project" />
112-
<orderEntry type="library" exported="" scope="TEST" name="sqlite4java-0.282" level="project" />
113113
<orderEntry type="library" exported="" scope="TEST" name="maven-ant-tasks-2.1.3" level="project" />
114+
<orderEntry type="library" exported="" scope="TEST" name="sqlite4java-0.282" level="project" />
114115
<orderEntry type="library" exported="" name="support-v4-22.1.1" level="project" />
115116
<orderEntry type="library" exported="" scope="TEST" name="mockable-android-22" level="project" />
116117
<orderEntry type="library" exported="" scope="TEST" name="shadows-core-3.0-rc3" level="project" />

OneSignalSDK/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ dependencies {
2828
compile project(':onesignal')
2929

3030
testCompile 'junit:junit:4.12'
31-
// testCompile 'org.robolectric:shadows-support-v4:3.0'
31+
testCompile 'org.robolectric:shadows-support-v4:3.0-rc3'
3232
testCompile('org.robolectric:robolectric:3.0-rc3') {
3333
exclude group: 'commons-logging', module: 'commons-logging'
3434
exclude group: 'org.apache.httpcomponents', module: 'httpclient'

OneSignalSDK/app/src/main/AndroidManifest.xml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,33 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:amazon="http://schemas.amazon.com/apk/res/android"
34
package="com.onesignal.example" >
45

6+
<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
7+
<permission android:name="com.onesignal.example.permission.RECEIVE_ADM_MESSAGE" android:protectionLevel="signature" />
8+
<uses-permission android:name="com.onesignal.example.permission.RECEIVE_ADM_MESSAGE" />
9+
510
<application
611
android:allowBackup="true"
712
android:icon="@mipmap/ic_launcher"
813
android:label="@string/app_name"
914
android:theme="@style/AppTheme" >
15+
16+
<!--
17+
<amazon:enable-feature android:name="com.amazon.device.messaging" android:required="false"/>
18+
<service android:name="com.onesignal.ADMMessageHandler" android:exported="false" />
19+
<receiver
20+
android:name="com.onesignal.ADMMessageHandler$Receiver"
21+
android:permission="com.amazon.device.messaging.permission.SEND" >
22+
<intent-filter>
23+
<action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
24+
<action android:name="com.amazon.device.messaging.intent.RECEIVE" />
25+
<category android:name="com.onesignal.example" />
26+
</intent-filter>
27+
</receiver>
28+
29+
-->
30+
1031
<activity
1132
android:name=".MainActivity"
1233
android:label="@string/app_name" >
@@ -19,19 +40,29 @@
1940
android:name=".MainActivity2Activity"
2041
android:label="@string/title_activity_main_activity2"
2142
android:exported="false" >
22-
<intent-filter>
43+
<!-- <intent-filter>
2344
<action android:name="com.onesignal.NotificationOpened.RECEIVE" />
2445
<category android:name="android.intent.category.DEFAULT" />
2546
</intent-filter>
47+
-->
2648
</activity>
27-
49+
<!--
2850
<receiver
2951
android:name="com.onesignal.example.TestNotificationOpenedReceiver"
3052
android:exported="false">
3153
<intent-filter>
3254
<action android:name="com.onesignal.NotificationOpened.RECEIVE" />
3355
</intent-filter>
3456
</receiver>
57+
58+
<receiver
59+
android:name="com.onesignal.example.OneSignalBackgroundDataReceiver"
60+
android:exported="false">
61+
<intent-filter>
62+
<action android:name="com.onesignal.BackgroundBroadcast.RECEIVE" />
63+
</intent-filter>
64+
</receiver>
65+
-->
3566
</application>
3667

3768
</manifest>
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
package com.onesignal.example;
22

33
import android.app.Activity;
4+
import android.content.Intent;
5+
import android.os.Bundle;
46

57
public class BlankActivity extends Activity {
6-
}
8+
9+
@Override
10+
protected void onCreate(Bundle savedInstanceState) {
11+
super.onCreate(savedInstanceState);
12+
System.out.println("BlankActivity onCreate!!!!");
13+
}
14+
15+
@Override
16+
protected void onNewIntent(Intent intent) {
17+
System.out.println("BlankActivity onNewIntent!!!!1");
18+
super.onNewIntent(intent);
19+
System.out.println("BlankActivity onNewIntent!!!!2");
20+
}
21+
}

OneSignalSDK/app/src/main/java/com/onesignal/example/MainActivity.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.onesignal.OneSignal;
1313
import com.onesignal.OneSignal.NotificationOpenedHandler;
1414

15+
import org.json.JSONArray;
1516
import org.json.JSONException;
1617
import org.json.JSONObject;
1718

@@ -36,23 +37,23 @@ protected void onCreate(Bundle savedInstanceState) {
3637
// Pass in your app's Context, Google Project number, OneSignal App ID, and a NotificationOpenedHandler
3738
OneSignal.init(this, "703322744261", "b2f7f966-d8cc-11e4-bed1-df8f05be55ba", new ExampleNotificationOpenedHandler());
3839
//OneSignal.init(this, "703322744261", "5eb5a37e-b458-11e3-ac11-000c2940e62c", new ExampleNotificationOpenedHandler());
39-
//OneSignal.enableInAppAlertNotification(false);
40-
//OneSignal.enableNotificationsWhenActive(true);
40+
OneSignal.enableInAppAlertNotification(true);
41+
OneSignal.enableNotificationsWhenActive(false);
4142
//OneSignal.setSubscription(false);
4243

43-
OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
44-
@Override
45-
public void idsAvailable(String userId, String registrationId) {
46-
Log.i("OneSignal Example:", "UserID: " + userId + ", RegId: " + (registrationId != null ? registrationId : "null"));
47-
48-
try {
49-
OneSignal.postNotification(new JSONObject("{'contents': {'en':'Test Message'}, 'include_player_ids': ['" + userId + "']}"), null);
50-
//OneSignal.postNotification(new JSONObject("{'contents': {'en':'Test Message'}, 'include_player_ids': ['" + "86480bb0-ef9a-11e4-8cf1-000c29917011', '2def6d7a-4395-11e4-890a-000c2940e62c" + "']}"), null);
51-
} catch (JSONException e) {
52-
e.printStackTrace();
53-
}
54-
}
55-
});
44+
// OneSignal.idsAvailable(new OneSignal.IdsAvailableHandler() {
45+
// @Override
46+
// public void idsAvailable(String userId, String registrationId) {
47+
// Log.i("OneSignal Example:", "UserID: " + userId + ", RegId: " + (registrationId != null ? registrationId : "null"));
48+
//
49+
// try {
50+
// OneSignal.postNotification(new JSONObject("{'contents': {'en':'Test Message'}, 'include_player_ids': ['" + userId + "']}"), null);
51+
// //OneSignal.postNotification(new JSONObject("{'contents': {'en':'Test Message'}, 'include_player_ids': ['" + "86480bb0-ef9a-11e4-8cf1-000c29917011', '2def6d7a-4395-11e4-890a-000c2940e62c" + "']}"), null);
52+
// } catch (JSONException e) {
53+
// e.printStackTrace();
54+
// }
55+
// }
56+
// });
5657
}
5758

5859
public void onSubscribeClicked(View v) {
@@ -110,6 +111,10 @@ private class ExampleNotificationOpenedHandler implements NotificationOpenedHand
110111
*/
111112
@Override
112113
public void notificationOpened(String message, JSONObject additionalData, boolean isActive) {
114+
Log.i("OneSignalExample", "message: " + message);
115+
Log.i("OneSignalExample", "additionalData: " + additionalData.toString());
116+
117+
/*
113118
String messageTitle = "OneSignal Example:" + isActive, messageBody = message;
114119
115120
try {
@@ -129,6 +134,7 @@ public void notificationOpened(String message, JSONObject additionalData, boolea
129134
.setCancelable(true)
130135
.setPositiveButton("OK", null)
131136
.create().show();
137+
*/
132138
}
133139
}
134140
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.onesignal.example;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.os.Bundle;
6+
import android.support.v4.content.WakefulBroadcastReceiver;
7+
import android.util.Log;
8+
9+
public class OneSignalBackgroundDataReceiver extends WakefulBroadcastReceiver {
10+
public void onReceive(Context context, Intent intent) {
11+
Bundle dataBundle = intent.getBundleExtra("data");
12+
13+
try {
14+
//Log.i("OneSignalExample", "NotificationTable content: " + dataBundle.getString("alert"));
15+
Log.i("OneSignalExample", "NotificationTable title: " + dataBundle.getString("title"));
16+
Log.i("OneSignalExample", "Is Your App Active: " + dataBundle.getBoolean("isActive"));
17+
Log.i("OneSignalExample", "data addt: " + dataBundle.getString("custom"));
18+
} catch (Throwable t) {
19+
t.printStackTrace();
20+
}
21+
}
22+
}

OneSignalSDK/app/src/test/java/com/onesignal/ShadowOneSignalRestClient.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
import com.loopj.android.http.JsonHttpResponseHandler;
77
import com.loopj.android.http.ResponseHandlerInterface;
88

9-
import org.apache.http.entity.StringEntity;
109
import org.json.JSONException;
1110
import org.json.JSONObject;
12-
import org.robolectric.annotation.Implementation;
1311
import org.robolectric.annotation.Implements;
14-
import org.robolectric.annotation.internal.Instrument;
1512

1613
import java.io.UnsupportedEncodingException;
1714

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.onesignal;
2+
3+
import android.app.Notification;
4+
import android.app.NotificationManager;
5+
6+
import org.robolectric.annotation.Implements;
7+
import org.robolectric.shadows.ShadowNotification;
8+
import org.robolectric.shadows.ShadowNotificationManager;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
import static org.robolectric.Shadows.shadowOf;
14+
15+
@Implements(NotificationManager.class)
16+
public class ShadowRoboNotificationManager extends ShadowNotificationManager {
17+
18+
public class PostedNotification {
19+
20+
PostedNotification(int id, ShadowNotification notif) {
21+
this.id = id; this.notif = notif;
22+
}
23+
24+
public int id;
25+
public ShadowNotification notif;
26+
}
27+
28+
public static ShadowNotification lastNotif;
29+
public static int lastNotifId;
30+
31+
public static List<PostedNotification> notifications = new ArrayList<PostedNotification>();
32+
33+
@Override
34+
public void notify(String tag, int id, Notification notification) {
35+
lastNotif = shadowOf(notification);
36+
lastNotifId = id;
37+
notifications.add(new PostedNotification(id, lastNotif));
38+
System.out.println("notification: " + lastNotif.getContentText());
39+
super.notify(tag, id, notification);
40+
//throw new RuntimeException("Get stack trace!");
41+
}
42+
43+
}

0 commit comments

Comments
 (0)