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

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?