Clear Android Browser History
I am writing an application for a client that will have several devices that are open to customers to look at and play with. They want to be able to clear the browser history on a regular basis so that if a customer opens the browser to an inappropriate web site the next customer to come along will not see this.
I am currently us开发者_如何学编程ing this to clear the history and searches:
Browser.clearHistory(getContentResolver());
Browser.clearSearches(getContentResolver());
This correctly clears the history. But any windows(tabs) that were open in the browser remain open. How can I tell the browser to close all of these tabs so that the next time someone opens the browser it will load the start page only?
I've noticed that killing the browser with the TaskManager that comes pre-loaded on the device works. Is killing the browser task the only way that I can get it to close any open tabs? If so how can I go about killing/restarting the browser process? I've tried this:
am = (ActivityManager) getApplicationContext().getSystemService(Activity.ACTIVITY_SERVICE);
am.killBackgroundProcesses("com.android.browser");
But this method doesn't seem to be doing anything. I do have
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"></uses-permission>
In my manifest but after I run this and go back to the browser it is still sitting on whatever tabs were left open. What is the proper way to use the permission that is granted by this?
Id rather find some way other than Task Kill to make it work, but at this point I am coming up empty on all fronts.
If your device is rooted, you can use the command below, to clear all data of the application. I don't know if this is applicable for each device, as it depends on the package manager
Runtime.getRuntime().exec("su -c /system/bin/pm clear com.android.browser");
I tried to close the browser via the ActivityManager and it works fine. I tested this on an HTC 2.2 and it works perfect.
Maybe you should also try this:
am.killBackgroundProcesses("com.google.android.browser");
in case the browser on your phone is not at com.android.browser
or even try to finish the activity: com.android.browser.BrowserActivity
Hope this helps!
Much like a computer browser, Android browsers will keep all records that you search onto the device. If you’re worried about browser history or don’t want any records in your Android, you can remove all browser history within minutes. After delete your browser records will delete all cache data where you’re login into Chrome.
精彩评论