android - 如何清除 android marshmallow 中的浏览历史记录

标签 android browser android-6.0-marshmallow

我正在清除 android 中的浏览器历史记录。直到 android 5.1.1 即; Lollipop 以下语法工作正常。

Browser.clearHistory(mContextUtility.getContentResolver());

但是,对于 android 6 即;棉花糖它不起作用。那么我该如何解决这个问题,有没有其他方法可以清除浏览器历史记录?

最佳答案

查看 Android 源代码,它看起来对您来说没有前途。请注意,clearHistory 方法不再执行任何操作,因此 canClearHistory 始终返回 false

/**
 * Returns whether there is any history to clear.
 *
 * @param cr   The ContentResolver used to access the database.
 * @return boolean  True if the history can be cleared.
 * @removed
 */
public static final boolean canClearHistory(ContentResolver cr) {
    return false;
}

/**
 *  Delete all entries from the bookmarks/history table which are
 *  not bookmarks.  Also set all visited bookmarks to unvisited.
 *
 *  @param cr   The ContentResolver used to access the database.
 *  @removed
 */
public static final void clearHistory(ContentResolver cr) {
}

以下是 5.1.1 r1 中的相同方法,当它们实际起作用时:

    public static final boolean More ...canClearHistory(ContentResolver cr) {
    Cursor cursor = null;
    boolean ret = false;
    try {
        cursor = cr.query(History.CONTENT_URI,
            new String [] { History._ID, History.VISITS },
            null, null, null);
        ret = cursor.getCount() > 0;
    } catch (IllegalStateException e) {
        Log.e(LOGTAG, "canClearHistory", e);
    } finally {
        if (cursor != null) cursor.close();
    }
    return ret;
}

Delete all entries from the bookmarks/history table which are not bookmarks. Also set all visited bookmarks to unvisited. Requires android.Manifest.permission Parameters: cr The ContentResolver used to access the database.

public static final void More ...clearHistory(ContentResolver cr) {
    deleteHistoryWhere(cr, null);
}

关于android - 如何清除 android marshmallow 中的浏览历史记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33689672/

相关文章:

android - 在具有固定宽度的 ImageView 中缩放图像

android - 通过在 xml 中设计来制作自定义组件

javascript - 当前浏览器中剪贴板的最大大小

javascript - 如何使浏览器自动访问 1000 个页面并在每个页面上触发一个简单的 javascript 函数?

c# - 如何将 AdBlock Plus 集成到 C# WebBrowser 控件中?

android - 以编程方式断开android Marshmallow版本中的调用

android - 强化 Android 检查

java - 目录创建在 Marshmallow Android 中不起作用

java - Android 6 crypto Cipher.update 不再像 Android 5 那样工作

java android R 无法解析为变量错误