3

I'm trying to develop an android application that could erase default browser's search history without rooting, but I'm stuck. Here is my source code

File file = new File("data/data/com.android.browser/databases/browser.db");

            try {

                String content = "";



                if(!file.exists()) {
                    file.createNewFile();
                }

                FileWriter fw = new FileWriter(file.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(content);
                bw.close();

                Toast.makeText(MainActivity.this, "History Deleted From Default Browser", Toast.LENGTH_LONG).show();

                System.out.println("Done");

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

As i know browser's history will be stored in "browser.db" file, i can able to clear history only if I change the permission of browser.db file in command prompt through adb shell like "chmod 777 data/data/com.android.browser/databases/browser.db" But i need to do it every time, i want to do this inside my application source code, I also tried Runtime.exec() methods to execute adb shell, actually History Eraser app can erase the history of default browser without root permission, Can any one please help me out in solving this mystery. Thanks in Advance.

12
  • you are tyring to break the sandbox - that won't work! checkhttp://stackoverflow.com/questions/7235741/programmatically-erase-android-browser-cache-history-etc-with-root?rq=1 Commented Jun 24, 2013 at 9:11
  • But there are lots of history cleaner apps like History Eraser for example can erase without rooting @LordT. If they can do it there has to be some way right ? Commented Jun 24, 2013 at 9:13
  • from JNI, you can run system() call, but not sure that works Commented Jun 24, 2013 at 9:15
  • @SIGSEGV even if we run we might need root acces isn't it ?End user afraid of rooting their mobiles, so I'm targetting the app to work in all kind of environment, But I'm stuck here. Any way thanks for your time. SIGSEGV Commented Jun 24, 2013 at 9:18
  • @ChethanShetty No, if you are able to run adb shell pm clear com.android.browser without rooting then system() call from jni will work i hope. Commented Jun 24, 2013 at 9:19

1 Answer 1

9

Add the following permissions to AndroidManifest.xml:

<uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>

Then when you want to clear the history use:

Browser.clearHistory(getContentResolver());
Sign up to request clarification or add additional context in comments.

2 Comments

cannot resolve the method clearHistory (android.content.contentresolver)
These permissions are removed in API 23 or above. So if you are targeting 23 or above this make some error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.