廊坊营销型网站建设,淄博外贸网站建设公司,附近找装修公司,网页制作模板大全接上一篇#xff1a;android aidl进程间通信封装通用实现-CSDN博客
该aar包的使用还是比较方便的
一先看客户端
1 初始化
JsonProtocolManager.getInstance().init(mContext, com.autoaidl.jsonprotocol);
//客户端监听事件实现
JsonProtocolManager.getInsta…接上一篇android aidl进程间通信封装通用实现-CSDN博客
该aar包的使用还是比较方便的
一先看客户端
1 初始化
JsonProtocolManager.getInstance().init(mContext, com.autoaidl.jsonprotocol);
//客户端监听事件实现
JsonProtocolManager.getInstance().setJsonProtocolReceive(new IJsonReceive() {Overridepublic String received(String jsonParams, Bundle bundle) {LogUtils.d(TAG, OnReceive -- jsonParams: jsonParams);return JsonSdkController.getInstance().onReceive(jsonParams);}
});
2 发送事件 就是通过json的形式将参数包裹进来另一端统一解析 唯一标志位KEY_CLIENT_REQUEST_AUTHOR 是必须要加的不然区分不出来是那个客户端
JSONObject jsonObject new JSONObject();
jsonObject.put(protocolId, ProtocolID.PROTOCOL_SEARCH);
jsonObject.put(versionName, v0.0.1);
JSONObject jsonData new JSONObject();
jsonData.put(say,hello- which pid are you ?);
jsonObject.put(data, jsonData);
jsonObject.put(SDKConstants.KEY_CLIENT_REQUEST_AUTHOR, yangtestt);
JsonProtocolManager.getInstance().request(jsonObject.toString(),null);
二再看服务端
1 初始化
JsonProtocolManager.getInstance().init(mContext, com.autoaidl.jsonprotocol);
2 发送事件
JSONObject jsonObject new JSONObject(); jsonObject.put(protocolId, ProtocolID.PROTOCOL_SEARCH); jsonObject.put(versionName, v0.0.1); JSONObject jsonData new JSONObject(); jsonData.put(say,hello- which pid are you ?); jsonObject.put(data, jsonData); //jsonObject.put(SDKConstants.KEY_CLIENT_REQUEST_AUTHOR, yangtestt); JsonProtocolManager.getInstance().request(jsonObject.toString(),null); 服务端和客户端相互发送比较类似只是服务端不需要传唯一id值
也不需要监听回调
我项目里的demo更简单直接将客户端和服务端的代码 放到一起公用了代码虽然冗余但能用demo中的服务端和客户端唯一的区别就是gradle里面动态改了包名。
实际项目中可以直接将lib库编译成aar包集成进去然后客户但android 11的版本需要
增加两部
1 增加权限
queriespackage android:namecom.autoaidl.jsonprotocol /intentaction android:namecom.auto.aidl.AidlService //intent
/queries
2 init的时候要传入服务端的包名
服务器端只需引入aar包就行了init的时候包名也可以传空。