Question

Using this code I managed to mark all missed calls as read:

ContentValues values = new ContentValues();
        values.put(Calls.NEW, 0);
        if (android.os.Build.VERSION.SDK_INT >= 14) {
            values.put(Calls.IS_READ, 1);
        }
        StringBuilder where = new StringBuilder();
        where.append(Calls.NEW);
        where.append(" = 1 AND ");
        where.append(Calls.TYPE);
        where.append(" = ?");

        context.getContentResolver().update(Calls.CONTENT_URI, values, where.toString(),
                new String[]{ Integer.toString(Calls.MISSED_TYPE) });

but in the android notification bar I still have a flag with missed calls. How can I also clear the notification bar for calls in android?

Was it helpful?

Solution

How can I also clear the notification bar for calls in android?

You don't. That Notification is put there by another app, and you have no means of controlling whether that Notification is displayed, short of building a ROM mod that changes the behavior of that other app.

UPDATE: Since this answer was originally written, NotificationListenerService was added and can clear notifications, but only on Android 4.3+.

OTHER TIPS

The only "legal" but extremely ugly and usually useless way to achieve what you want is to show Call Log to user. And I mean literally show (becomes visual, gets focus). In case you want to do this, here's how:

public static boolean showCallLog(Context context)
{
    try
    {
        Intent showCallLog = new Intent();
        showCallLog.setAction(Intent.ACTION_VIEW);
        showCallLog.setType(android.provider.CallLog.Calls.CONTENT_TYPE);
        context.startActivity(showCallLog);
        return true;
    }
    catch (Exception e)
    {
        Log.d("Couldn't show call log.", e.getMessage());
    }
    return false;
}

The reason behind this mess is the fact that apps authoritatively responsible for call logging and notifying users about missed calls (stock phone apps) use cached values. Why? Because of overall performance. You need to somehow notify those apps that Call Log has changed (seen means changed, as well) and that it should update it. It would be nice if all such apps on all devices would receive a broadcast in order to refresh, but as far as I know, it's not the case.

I hope someone will find a better way (without interrupting the user) to force refresh on stock phone apps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top