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 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧