How to get browser history in android?

I would like to implement an application to get the default browser history of android by default and save the browser history in an XML file. But browser history is not saved on some devices in an xml file.

I ran my application to get browser history information for saving in 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(); } } 

Using the method described above, I can get the browser history and save the data in an xml file on sdcard. But on some Android devices there is no browser history and is not saved in the xml file. If I test the application on a Motorola Droid device, then it works fine. But if I test one application on the tested application npm702 NOVO7PALADIN, then I can not get the browser history in my XML file.

+7
source share
1 answer

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

Secondly, Browser.BOOKMARKS_URI , at best, will work for an open source application that is part of the Android Open Source Project. Device manufacturers can replace this application with something else that will not record their history, bookmarks or anything else in this ContentProvider . Similarly, users are allowed to download third-party browsers that may not store things in this ContentProvider .

Thirdly, NOVO7PALADIN may not have passed the compatibility test kit, especially if it does not have a pre-installed Google Play Store (previously the Android Market). This would mean that the device manufacturer can rip whatever it wants, including whether the open-source browser application saves things in ContentProvider .

You need to contact the manufacturer NOVO7PALADIN to find out something else.

+9
source

All Articles