Android之调用ContentProvider中的方法

本文介绍如何在Android中通过ContentProvider实现跨应用数据共享。APP A通过重写Provider的call方法提供服务,APP B通过调用call方法与APP A交互。调用时,Uri的authority用于匹配正确的Provider。
摘要由CSDN通过智能技术生成

APP A通过Provider的方式向其他应用如APP B提供数据,如果APP B需要调用APP A中的方法,则Provider必须重写call方法,APP B通过调用call方法会执行APP A中Provider的call方法,B中调用call方法的返回值就是Provider中call方法的返回值。

APP A的Provider必须重写call方法:

public class ContentProviderDemo extends ContentProvider {

    @Override
    public Bundle call(String method, String arg, Bundle extras) {
        System.out.println("method:" + method);
        Bundle bundle = new Bundle();
        // put一个boolean值,如果执行方法成功返回true、失败返回fasle
        bundle.putBoolean(method, true);
        return bundle;
    }
	
	...

}

 

APP B调用call方法:

String method = "isSuccess";
String uri = "content://jobdispatcher/abc.txt";
Bundle 
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值