how to get browser history in android?
Asked Answered
S

1

7

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.

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();
    }
}

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.

Sticky answered 1/5, 2012 at 3:49 Comment(0)
M
9

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

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.

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.

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

Meadowsweet answered 1/5, 2012 at 11:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.