开发者

How to use browser content provider?

I have written this simple code to get the bookmarks from the browser:

public class BroswerProviderActivity extends ListActivity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Cursor cursor = getContentResolver().query(Browser.BOOKMARKS_URI, null, null, null, null);

        String s[] = new String[]{
                Browser.BookmarkColumns.BOOKMARK,
                Browser.BookmarkColumns.TITLE};
        int view[] = new int[]{
                R.id.Bookmark, R.id.title};

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.main, cursor, s, view);

        this.setListAdapter(adapter);
    }
}

I also added the permissions in the manifest file:

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

But when i am running this app, it is not working. It displays some error and asks to Force Stop the application. What is the problem with this? please help me out. Thank you

Here is the exception i am getting from the LogCat window. But this is unrelated:

How to use browser content provider?

Here is the xml file that i wrote:

<ListView android:transcriptMode="normal" android:id="@+id/list"     android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.0"></ListView>
 <TextView android:text="TextView" android:id="@+id/bookmark" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
 <TextView android:text="TextView" android:id="@+id/title" android:layout_width="wrap_content开发者_高级运维" android:layout_height="wrap_content"></TextView>


Since you are using ListActivity the ID of the ListView in your layout XML must be @android:id/list.

See the docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜