gpt4 book ai didi

android - 检查 Android 内容 Uri

转载 作者:行者123 更新时间:2023-11-29 00:26:49 26 4
gpt4 key购买 nike

我有两个应用程序。 App B 有一个 ContentProvider,App A 可以与之交互。不需要应用程序 B。如果我查询 App B 内容,我会在未安装 App B 时收到此错误:

Unknown URL content://com.appb.provider

现在我知道它在应用程序 B 存在时有效,但我没有意识到如果提供程序不存在,查询会崩溃。我们应该如何在查询之前检查自定义提供程序? ContentResolver 中没有明显的 bool 检查,我想我可以使用:

getContentResolver().acquireContentProviderClient()

但这似乎很严厉。有没有更好的方法来检查提供程序是否存在?

最佳答案

我找到了一个不错的解决方案:

getContentResolver().getType()

您可以检查 null 而不必担心释放客户端。仍然对更好的选择持开放态度。

关于android - 检查 Android 内容 Uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18732326/

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