clear missed calls and clear notification from android bar

前端 未结 2 1893
渐次进展
渐次进展 2021-01-28 09:54

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

ContentValues values = new ContentValues();
        values.put(Calls.NEW, 0);
        if (android.os.         


        
2条回答
  •  无人及你
    2021-01-28 10:04

    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.

提交回复
热议问题