@@ -1497,6 +1497,74 @@ public static void cancelNotification(int id) {
1497
1497
NotificationManager notificationManager = (NotificationManager )appContext .getSystemService (Context .NOTIFICATION_SERVICE );
1498
1498
notificationManager .cancel (id );
1499
1499
}
1500
+
1501
+
1502
+ public static void cancelGroupedNotifications (String group ) {
1503
+ if (appContext == null ) {
1504
+ Log (LOG_LEVEL .ERROR , "OneSignal.init has not been called. Could not clear notifications part of group " + group );
1505
+ return ;
1506
+ }
1507
+
1508
+ NotificationManager notificationManager = (NotificationManager )appContext .getSystemService (Context .NOTIFICATION_SERVICE );
1509
+
1510
+ OneSignalDbHelper dbHelper = OneSignalDbHelper .getInstance (appContext );
1511
+ Cursor cursor = null ;
1512
+
1513
+ try {
1514
+ SQLiteDatabase readableDb = dbHelper .getReadableDbWithRetries ();
1515
+
1516
+ String [] retColumn = { NotificationTable .COLUMN_NAME_ANDROID_NOTIFICATION_ID };
1517
+
1518
+ String whereStr = NotificationTable .COLUMN_NAME_GROUP_ID + " = ? AND " +
1519
+ NotificationTable .COLUMN_NAME_DISMISSED + " = 0 AND " +
1520
+ NotificationTable .COLUMN_NAME_OPENED + " = 0" ;
1521
+ String [] whereArgs = { group };
1522
+
1523
+ cursor = readableDb .query (
1524
+ NotificationTable .TABLE_NAME ,
1525
+ retColumn ,
1526
+ whereStr ,
1527
+ whereArgs ,
1528
+ null , null , null );
1529
+
1530
+ while (cursor .moveToNext ()) {
1531
+ int notifId = cursor .getInt (cursor .getColumnIndex (NotificationTable .COLUMN_NAME_ANDROID_NOTIFICATION_ID ));
1532
+ if (notifId != -1 )
1533
+ notificationManager .cancel (notifId );
1534
+ }
1535
+ }
1536
+ catch (Throwable t ) {
1537
+ OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "Error getting android notifications part of group: " + group , t );
1538
+ }
1539
+ finally {
1540
+ if (cursor != null && !cursor .isClosed ())
1541
+ cursor .close ();
1542
+ }
1543
+
1544
+ SQLiteDatabase writableDb = null ;
1545
+ try {
1546
+ writableDb = dbHelper .getWritableDbWithRetries ();
1547
+ writableDb .beginTransaction ();
1548
+
1549
+ String whereStr = NotificationTable .COLUMN_NAME_GROUP_ID + " = ? AND " +
1550
+ NotificationTable .COLUMN_NAME_OPENED + " = 0 AND " +
1551
+ NotificationTable .COLUMN_NAME_DISMISSED + " = 0" ;
1552
+ String [] whereArgs = { group };
1553
+
1554
+ ContentValues values = new ContentValues ();
1555
+ values .put (NotificationTable .COLUMN_NAME_DISMISSED , 1 );
1556
+
1557
+ writableDb .update (NotificationTable .TABLE_NAME , values , whereStr , whereArgs );
1558
+ BadgeCountUpdater .update (writableDb , appContext );
1559
+
1560
+ writableDb .setTransactionSuccessful ();
1561
+ } catch (Throwable t ) {
1562
+ OneSignal .Log (OneSignal .LOG_LEVEL .ERROR , "Error marking a notifications with group " + group + " as dismissed! " , t );
1563
+ } finally {
1564
+ if (writableDb != null )
1565
+ writableDb .endTransaction ();
1566
+ }
1567
+ }
1500
1568
1501
1569
public static void removeNotificationOpenedHandler () {
1502
1570
getCurrentOrNewInitBuilder ().mNotificationOpenedHandler = null ;
0 commit comments