如何访问android中的默认浏览器历史记录?

时间:2014-03-27 14:02:15

标签: android android-browser

我正在尝试访问android中的默认browser(chrome)历史记录,但无法获得任何结果。 我想访问历史记录(网址)并希望在url中显示listview。我也包括在内 我从website获得了帮助 下面是我的代码

activity_main.xml中

    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
  </ListView>

MainActivity.java

public class MainActivity extends Activity {

    ListView listView;
    ArrayList<String> values = new ArrayList<String>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = (ListView) findViewById(R.id.list);

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, android.R.id.text1, values);

        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                int itemPosition = position;

                String itemValue = (String) listView
                        .getItemAtPosition(position);

                Toast.makeText(
                        getApplicationContext(),
                        "Position :" + itemPosition + "  ListItem : "
                                + itemValue, Toast.LENGTH_LONG).show();
            }    });
    }



    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) {

                String s = mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX);
                values.add(s);
                mCur.moveToNext();
            }
        }
    }

}

0 个答案:

没有答案