gpt4 book ai didi

android - RESTFul Android ContentProvider URI

转载 作者:搜寻专家 更新时间:2023-11-01 09:10:10 24 4
gpt4 key购买 nike

为了实现 RESTful,获取帖子评论的 URI 应该类似于:

posts/#/comments

# 是帖子 ID,它会根据您感兴趣的帖子而改变。

我想在设计我的内容提供商的内容 URI 时应用一些约定。问题是,内容提供者的用户如何以优雅的方式构建这样的 URI?

一个可行的解决方案是:

//in PostProvider
public static URI CONTENTS_URI_POSTS = Uri.parse("content://" + AUTHORITY + "/posts");
public static String COMMENTS = "comments";

然后用户将使用Uri.builder 组合CONTENTS_URI_POSTS + id + COMMENTS。但是,此方法公开了有关如何构建 URI 的详细信息。

要隐藏细节,也许我可以添加一个方法:

 public static URI  buildContentUriToGetPostComments(int post_id);

有更好的主意吗?谢谢!

最佳答案

您可以为帖子及其评论使用不同的路径:

content://<authority>/posts/#<post-id>
content://<authority>/comments/#<post-id>

这样你就有了一个看起来更传统的 URI 并且在内容提供者中更容易处理,你不需要解析 URI 但一个标准的 UriMatcher 就可以了。

关于android - RESTFul Android ContentProvider URI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8785283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com