gpt4 book ai didi

android - 什么是 getContentResolver().call() 以及如何使用它

转载 作者:太空宇宙 更新时间:2023-11-03 12:09:08 24 4
gpt4 key购买 nike

我已经阅读了 Android 上的文档 ContentResolver

我也找过合适的例子,没找到。

根据文档,有一个方法call,可以在标准内容提供者方法不足时用作访问自定义提供者方法的方法:

final Bundle     call(Uri uri, String method, String arg, Bundle extras)
Call a provider-defined method.

所以在我的代码中我执行:

getContentResolver().call(uri, method, arg, extras);

但它总是返回 null bundle。事实上,provider 中的方法永远不会被调用。

进一步的研究指出了契约(Contract)的(感知​​的)差异,其中 RESOLVER 有一个 uri 参数 没有等效的 PROVIDER 参数:

Bundle   call(String method, String arg, Bundle extras)
Call a provider-defined method.

我显然不明白什么。谁能指出我正确的方向?

最佳答案

Further research points to a discrepancy of the contract where the RESOLVER has a uri argument with no equivalent PROVIDER parameter

他们就是这样写的。 Uri 只是用来识别 ContentProvider -- ContentProvider 知道它是谁,因此不需要 Uri.

the provider method does not allow @Override annotation

是的,正如您在 this sample ContentProvider 中看到的那样:

  @Override
public Bundle call(String method, String arg, Bundle extras) {
if (SET_KEY_METHOD.equals(method) && arg != null) {
key=arg;
}

return(null);
}

但是,您的构建目标(例如,在 Eclipse 中,项目 > 属性 > Android)必须设置为 API 级别 11 或更高级别。

来自the client的相应call()看起来像:

getContentResolver().call(Provider.Constants.CONTENT_URI,
Provider.SET_KEY_METHOD, "sekrit", null);

Yes. I have a method in the provider that is declared 'public' that is passed into the contentresolver argument 'method.'

这不是它的工作原理。 ContentResolver 上的 call() 调用 ContentProvider 上的 call()

关于android - 什么是 getContentResolver().call() 以及如何使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17224766/

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