如何让浏览器历史记录中的android?历史记录、浏览器、android

2023-09-04 23:25:32 作者:山后别相逢.

我想实现一个应用程序获取的Andr​​oid默认浏览器的历史记录和保存浏览器历史记录到一个XML file.But浏览器历史记录中不保存在一些设备到一个XML文件中。

I would like to implement an application to get android default browser history and saving the browser history to an xml file.But the browser history is not saving in some devices into an xml file.

我已经实现了我的申请得到浏览器历史信息保存到xml文件如下:

I have implemented my application for get the browser history info to save to xml file as follows:

private void browserHistoryDOM() {
    try{
        File newxmlfile = new File("/sdcard/Xmlfiles/briwserHistory.xml");
        newxmlfile.createNewFile();
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        Document document = documentBuilder.newDocument();
        Element rootElement = document.createElement("root");
        document.appendChild(rootElement);

        Cursor mCur = managedQuery(Browser.BOOKMARKS_URI,Browser.HISTORY_PROJECTION, null, null, null);
        mCur.moveToFirst();

        if (mCur.moveToFirst() && mCur.getCount() > 0) {
            while (mCur.isAfterLast() == false) {
                Element em = document.createElement("bookmarkIdx");
                em.appendChild(document.createTextNode(mCur.getString(Browser.HISTORY_PROJECTION_BOOKMARK_INDEX)));
                rootElement.appendChild(em);

                long callDate = Long.parseLong(mCur.getString(Browser.HISTORY_PROJECTION_DATE_INDEX));
                SimpleDateFormat datePattern = new SimpleDateFormat ("dd-MM-yyyy/h:m:s:a");
                datePattern.setTimeZone(TimeZone.getTimeZone("GMT"));
                String date_str = datePattern.format(new Date(callDate));

                Element em1 = document.createElement("dateIdx");
                em1.appendChild(document.createTextNode(date_str));
                rootElement.appendChild(em1);

                Element em2 = document.createElement("idIdx");
                em2.appendChild(document.createTextNode(mCur.getString(Browser.HISTORY_PROJECTION_ID_INDEX)));
                rootElement.appendChild(em2);

                Element em3 = document.createElement("titleIdx");
                em3.appendChild(document.createTextNode(mCur.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX)));
                rootElement.appendChild(em3);

                Element em4 = document.createElement("urlIdx");
                em4.appendChild(document.createTextNode(mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX)));
                rootElement.appendChild(em4);

                Element em5 = document.createElement("visitsIdx");
                em5.appendChild(document.createTextNode(mCur.getString(Browser.HISTORY_PROJECTION_VISITS_INDEX)));
                rootElement.appendChild(em5);

                long searchDate = Long.parseLong(mCur.getString(Browser.SEARCHES_PROJECTION_DATE_INDEX));
                SimpleDateFormat datePattern1 = new SimpleDateFormat ("dd-MM-yyyy/h:m:s:a");
                datePattern1.setTimeZone(TimeZone.getTimeZone("GMT"));
                String date_str1 = datePattern.format(new Date(searchDate));

                Element em6 = document.createElement("searchDateIdx");
                em6.appendChild(document.createTextNode(date_str1));
                rootElement.appendChild(em6);

                Element em7 = document.createElement("searchIdx");
                em7.appendChild(document.createTextNode(mCur.getString(Browser.SEARCHES_PROJECTION_SEARCH_INDEX)));
                rootElement.appendChild(em7);

                Element em8 = document.createElement("truncateIdIdx");
                em8.appendChild(document.createTextNode(mCur.getString(Browser.TRUNCATE_HISTORY_PROJECTION_ID_INDEX)));
                rootElement.appendChild(em8);

                Element em9 = document.createElement("truncateOldest");
                em9.appendChild(document.createTextNode(mCur.getString(Browser.TRUNCATE_N_OLDEST)));
                rootElement.appendChild(em9);

                mCur.moveToNext();
            }
        }

        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(document);
        StreamResult result = new StreamResult(newxmlfile);
        transformer.transform(source, result);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

通过使用上面的方法,我可以让浏览器历史记录,并能够保存数据到XML文件上sdcard.But某种Android设备没有得到浏览器的历史完全地和不保存为XML文件。如果我考摩托罗拉Droid设备上的应用程序,然后它正在fine.But如果我考了相同的应用程序在我测试的npm702 NOVO7PALADIN应用程序,然后我不能够让浏览器的历史记录在我的XML文件中。

By using the above method i can get the browser history and able to save the data into xml file on sdcard.But in some kind of android devices are not getting browser history completly and not saving into xml file.If I test the app on Motorola Droid device then it is working fine.But If I test the same app on I have tested app on npm702 NOVO7PALADIN then i am not able to get browser history in my xml file.

推荐答案

首先,永远不要硬线 / SD卡。使用 Environment.getExternalStorageDirectory()去外部存储的根。

First, never hardwire /sdcard. Use Environment.getExternalStorageDirectory() to get to the root of external storage.

其次, Browser.BOOKMARKS_URI 会,顶多为开源浏览器的应用程序,是Android开源项目的一部分工作。设备制造商,欢迎来代替别的东西不会被记录的历史记录,书签,或其他任何东西在的ContentProvider 该应用程序。同样地,允许用户下载第三方浏览器,这可能不会在这里存放的东西在的ContentProvider

Second, Browser.BOOKMARKS_URI will, at most, work for the open source Browser app that is part of the Android Open Source Project. Device manufacturers are welcome to replace that app with something else that will not be recording its history, bookmarks, or anything else in that ContentProvider. Similarly, users are allowed to download third-party browsers, which may not be storing things in that ContentProvider.

三,NOVO7PALADIN可能没有通过兼容性测试套件,特别是如果它不具备谷歌Play商店(原Android Market的)pre-安装。这意味着设备制造商的欢迎,打破呼风唤雨,包括存储是开源的浏览器应用程序的东西在的ContentProvider

Third, NOVO7PALADIN may not have passed the Compatibility Test Suite, particularly if it does not have the Google Play Store (formerly Android Market) pre-installed. That would mean that the device manufacturer is welcome to break anything they want, including whether the open source Browser app stores things in that ContentProvider.

您需要联系NOVO7PALADIN制造商,了解更多的东西。

You would need to contact the NOVO7PALADIN manufacturer to learn anything more.