How can I call a custom method in ContentProvider via ContentResolver and subsequently access the Bundle?

I have my own save() method in my ContentProvider MyContentProvider class that I want to call through ContentResolver. The goal is to pass the POJO as a Bundle to MyContentProvider .

I use the call method, as indicated here , and defined here .

I have no mistakes. This method is simply not available.

(abbreviated), a custom ContentProvider with a custom method is as follows:

 public class MyContentProvider extends ContentProvider { public void save() { Log.d("Test method", "called"); } } 

I call it this way:

 ContentResolver contentResolver = context.getContentResolver(); Bundle bundle = new Bundle(); bundle.putSerializable("pojo", getPojo()); contentResolver.call(Contracts.CONTENT_URI, "save", null, bundle); 

Why has the save method never been called, and if I get to this point, how do I access the called Uri and Bundle in the save() method? I could not find any link for this anywhere on SO or the Internet.

Thank you for your responses!

+7
source share
2 answers

I just played with this to set up a custom function. As noted in a comment on your question, the key implements the call () method in the content provider to handle various methods that you could pass.

My call to ContentResolver is as follows:

 ContentResolver cr = getContentResolver(); cr.call(DBProvider.CONTENT_URI, "myfunction", null, null); 

Inside the ContentProvider, I implemented a call function, and it checks the method name passed to:

 @Override public Bundle call(String method, String arg, Bundle extras) { if(method.equals("myfunction")) { // Do whatever it is you need to do } return null; } 

It seems to work.

+16
source

If you want to override your own ContentProvider, you need to override this method:

  • Oncreate ()
  • request()
  • Delete ()
  • insert()
  • update ()
  • GetType ()

But the save () method is not in the ContentProvider life cycle and cannot be called.

-2
source

All Articles