Ope*_*aus 9 android android-contentresolver android-contentprovider
我save()在自定义ContentProvider类中有一个自定义方法MyContentProvider,我想通过ContentResolver调用它.目标是将POJO作为Bundle传递给MyContentProvider.
我没有得到任何错误.该方法无法访问.
使用自定义方法的(缩短的)自定义ContentProvider如下所示:
public class MyContentProvider extends ContentProvider {
public void save() {
Log.d("Test method", "called");
}
}
Run Code Online (Sandbox Code Playgroud)
我称之为:
ContentResolver contentResolver = context.getContentResolver();
Bundle bundle = new Bundle();
bundle.putSerializable("pojo", getPojo());
contentResolver.call(Contracts.CONTENT_URI, "save", null, bundle);
Run Code Online (Sandbox Code Playgroud)
为什么这个save方法永远不会被调用,如果我到达这一点,我如何在save()方法中访问被调用的Uri和Bundle ?我无法在SO或网络上找到任何参考资料.
谢谢您的回答!
And*_*rew 20
我一直在玩这个以获得自定义功能.正如您对问题的评论所述,关键是在内容提供程序中实现call()方法,以处理您可能传递的各种方法.
我对ContentResolver的调用如下所示:
ContentResolver cr = getContentResolver();
cr.call(DBProvider.CONTENT_URI, "myfunction", null, null);
Run Code Online (Sandbox Code Playgroud)
在ContentProvider中,我实现了调用函数,并检查传入的方法名称:
@Override
public Bundle call(String method, String arg, Bundle extras) {
if(method.equals("myfunction")) {
// Do whatever it is you need to do
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
这似乎有效.
| 归档时间: |
|
| 查看次数: |
6887 次 |
| 最近记录: |