When extracting URLs from browser history it shows Cannot resolve symbol 'BookmarkColumns'

892 Views Asked by At

I'm trying to extract URLs from browser history. I've found below code and try to implement it. But the problem is it gives error in BookmarkColumns, BOOKMARKS_URI, noicon.

I tryed this in API levels 16,23,25. But the error dosent solve. It always says that "Cannot resolve symbol 'BookmarkColumns' "

Please help me to resolve this...

import android.content.ContentResolver;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.provider.Browser;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;


public class MainActivity extends AppCompatActivity {

    private ArrayList<String> titles;
    private ArrayList<String> urls;
    private ArrayList<Bitmap> bitmaps;
    private ContentResolver cr;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        createLists();
    }

    protected void onResume() {
        super.onResume();
        getBH();
        showHistoryBookmarks();

    }

    public void createLists() {
        titles = new ArrayList<String>();
        urls = new ArrayList<String>();
        bitmaps = new ArrayList<Bitmap>();

    }

    public void getBH() {
        Bitmap icon;
        cr = getContentResolver();
        String order = Browser.BookmarkColumns.DATE + " DESC";
        String[] projection = {Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL, Browser.BookmarkColumns.FAVICON};
        //String selection=projection[0]+"=?";
        //String args[]={"Google"};
        Cursor rows = cr.query(Browser.BOOKMARKS_URI, projection, null, null, order);
        if (rows.getCount() > 0) {
            while (rows.moveToNext()) {
                //read title
                String title = rows.getString(rows.getColumnIndex(projection[0]));
                //read url
                String url = rows.getString(rows.getColumnIndex(projection[1]));
                //read icon
                byte[] bicon = rows.getBlob(rows.getColumnIndex(projection[2]));
                if (bicon != null) {
                    //convert blob image data to Bitmap
                    icon = BitmapFactory.decodeByteArray(bicon, 0, bicon.length);

                } else {
                    //default icon for history and bookmarks that do not icons
                    icon = BitmapFactory.decodeResource(getResources(), R.drawable.noicon);
                }
                //add to lists
                addToList(title, url, icon);
            }
            //close the cursor
            rows.close();
        }


    }


    public void addToList(String title, String url, Bitmap bitmap) {

        titles.add(title);
        urls.add(url);
        bitmaps.add(bitmap);

    }


    public void showHistoryBookmarks() {
        ListView l = (ListView) findViewById(R.id.hb_list);
        if (l != null) {
            if (titles.size() > 0) {
                ListAdapterModel aa = new ListAdapterModel(this, R.layout.listlayout, R.id.hbtitle, titles, urls, bitmaps);
                l.setAdapter(aa);
            } else {
                Toast.makeText(this, "This is no bookmark or history.", Toast.LENGTH_SHORT).show();
            }
        }

    }
}
1

There are 1 best solutions below

0
kiwDroid On

try these chrome history API. Read documents and give a try. I didn't try it. But thought would be insperation.