0

i have to remove missed calls from notification bar in onCreate, how ever set all "unread" to "read" is not enough

public void resetMissingCalls() {
    Runnable reset = new Runnable() {

        @Override
        public void run() {
            String[] projection = { CallLog.Calls._ID,
                    CallLog.Calls.CACHED_NUMBER_LABEL, CallLog.Calls.TYPE };
            String where = CallLog.Calls.TYPE + "=" + CallLog.Calls.MISSED_TYPE
                    + " AND " + CallLog.Calls.NEW + "=1";
            Cursor c = getContentResolver().query(
                    CallLog.Calls.CONTENT_URI, projection, where, null, null);
            Utils.PrintInfo("CALLS " + c.getCount());

            c.moveToFirst();
            if (c.getCount() > 0) {
                do {
                    Utils.PrintInfo(c.getString(c
                            .getColumnIndex(CallLog.Calls._ID)) + " coursor "+c.getString(c
                            .getColumnIndex(CallLog.Calls.CACHED_NUMBER_LABEL)));
                    setAsRead(c.getString(c
                            .getColumnIndex(CallLog.Calls._ID)));
                } while (c.moveToNext());
            }
            c.close();
        }
    };
    new Handler().post(reset);
}

how to clear this without using NotificationManager.cancelAll()

Mariusz
  • 1,352
  • 1
  • 16
  • 31
  • Are you getting id for notification that you need to remove? – MysticMagicϡ Oct 20 '14 at 09:26
  • nope im not, but maybe i can but i dont know how get id from notification itself – Mariusz Oct 20 '14 at 09:33
  • You can use [getActiveNotification](http://developer.android.com/reference/android/service/notification/NotificationListenerService.html#getActiveNotifications%28%29), parse the data you receive, and check a way to determine if its a missed call's notification, then cancel that notification. – MysticMagicϡ Oct 20 '14 at 09:38
  • `getActiveNotification` required change in secure setting, this is another thing i dont want to change – Mariusz Oct 20 '14 at 09:52

1 Answers1

0

if you want cancel all notification use

NotificationManager notifManager= (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notifManager.cancelAll();

but if you have notify id use

notifManager.cancel(notifyId);

if you want to listen to android notification , you need register to AccessibilityService

you may have to look at this answer

Community
  • 1
  • 1
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
  • fine but tell me how to get id of notification from topbar – Mariusz Oct 20 '14 at 09:34
  • when you create notification , notify (int id, Notification notification) that is the unique id , you can use it to cancel this notify , read about this here http://developer.android.com/reference/android/app/NotificationManager.html#notify(int, android.app.Notification) – Mina Fawzy Oct 20 '14 at 09:40
  • but i do not create notification about missing call this is system missing calls notification – Mariusz Oct 20 '14 at 09:46