public void getBrowserHist() {
Cursor mCur = managedQuery(Browser.BOOKMARKS_URI,
Browser.HISTORY_PROJECTION, null, null, null);
mCur.moveToFirst();
if (mCur.moveToFirst() && mCur.getCount() > 0) {
while (mCur.isAfterLast() == false) {
Log.v("titleIdx", mCur
.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX));
Log.v("urlIdx", mCur
.getString(Browser.HISTORY_PROJECTION_URL_INDEX));
mCur.moveToNext();
}
}
}
Add below uses-permission into your manifest file.
<uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
Enjoy :-)
Don’t forget to provide feedback or follow this blog, if you find this blog is useful.
where to implement this code?
ReplyDeletethanks.
Hello,
DeleteYou can Call above function from your button click event of GetHistory Button or call it from your onCreate() method also.
How i can use ListView for history and bookmarks?
ReplyDeleteHello,
DeleteStore Titles and Urls into array and then you can easily display this data in listview.
I need fast some code for it!
DeletePlease write some easy code.
I was try many codes, but I still failed!
Hello,
DeleteFirst Define 2 Arraylist, first for Titles and second for Urls
ArrayList mTitles=new ArrayList();
ArrayList mUrls=new ArrayList();
and then write below code for add Titles and Urls into while loop.
mTitles,add(mCur.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX));
mUrls,add(mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX));
Can you provide me the full code with main and manifest file.??
ReplyDeleteActivity_main::---
Delete--------------------------------------------------------
MainActivity.java::------
import java.util.ArrayList;
import android.os.Bundle;
import android.provider.Browser;
import android.app.Activity;
import android.database.Cursor;
import android.util.Log;
import android.view.Menu;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView view = (TextView) findViewById(R.id.hello);
String[] projection = new String[] {
Browser.BookmarkColumns.TITLE
, Browser.BookmarkColumns.URL
};
Cursor mCur = managedQuery(android.provider.Browser.BOOKMARKS_URI,
projection, null, null, null
);
mCur.moveToFirst();
int titleIdx = mCur.getColumnIndex(Browser.BookmarkColumns.TITLE);
int urlIdx = mCur.getColumnIndex(Browser.BookmarkColumns.URL);
while (mCur.isAfterLast() == false) {
view.append("n" + mCur.getString(titleIdx));
view.append("n" + mCur.getString(urlIdx));
mCur.moveToNext();
}
}
}
--------------------------------------------------------
Manifest.xml:::-----------
please I would be surely thankful to you if you could please provide me with the source code
ReplyDeletethanks
Hi
ReplyDeleteIs it possible to get other browsers history(not default browser) in android mobile?
in my code we can get all the browser history..
ReplyDeleteplease any body provide the source code for favorites or bookmark in android.
Deleteplease provide code for all browser history.
Deletei can get only default browser history
This code working for Chrome and Internet explorer only,not for Mozilla Firefor.
DeleteHow to get the history from firefox.(kindly send yr reply to this mail also-jeeva2k10@gmail.com)
Thanks
@Mandani Navneet, please share the source code to get only default browser history.
Delete@jeeva nandham, not working for chrome or other, always cursor.getCount = 0;
DeleteThis comment has been removed by the author.
ReplyDeletein my project i need to get get date and time with browser history . when i try to get date and time it gives null .
ReplyDeletecan you help me plz
Can you guide me on how to get the date and time for the browser history.
ReplyDeleteThis is my email: tansc6@gmail.com
Thank you in advance.
can you tell me how to clear history and give me full code of java file
ReplyDeleteI'm getting both bookmarks and history as a single thing how can i differentiate both?
ReplyDeleteNice method to transfer content, quite helpful.
ReplyDeletehow to delete the browser history api level above 23
ReplyDeletehow to make a browser that stores it's history and bookmarks like other browser's uc browser and opera and dolphin
ReplyDeleteThose APIs were removed in the Android 7.0 SDK, IIRC. They were never a particularly good idea in the first place. Is there anything we can do?
ReplyDelete