clcurie_11 2013-07-23 06:46 采纳率: 6.7%
浏览 2425

如何使用浏览器的 content provider?

我创建了下面简单的代码从浏览器中获得书签:

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);
    }
}

我也在manifest文件中添加了权限:

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

但是当我运行这个程序时,不能执行,显示一些错误,要求强制停止程序。如何解决这个问题?
这是我从LogCat窗口中获得的异常,但是这是不相关的:
CSDN移动问答

我创建的XML文件:

<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>
  • 写回答

1条回答

  • JaveZh 2013-07-23 07:03
    关注

    1.你如果要继承ListActivity,就不需要setContentView().去掉setContentView(R.layout.main);
    程序就可以运行了
    2.你如果要用main,把extends ListActivity 改成extends Activity,然后去findViewById那个ListView再设置adapter

    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题