当前位置: 首页 > news >正文

aspnet东莞网站建设大淘客cms网站建设

aspnet东莞网站建设,大淘客cms网站建设,网络实施方案,承德信息网58书接上回,继续第三种方式,是手动生成 service binder 的方法,项目结构 1,编译aidl aidl 文件保持不变,如何生成Bn和Bp 文件呢。 aidl -I ./libserviceaidl/aidl -h ./ -o ./ --langcpp libserviceaidl/aidl/com/test/IService.a…

书接上回,继续第三种方式,是手动生成 service binder 的方法,项目结构

1,编译aidl

aidl 文件保持不变,如何生成Bn和Bp 文件呢。

aidl -I ./libserviceaidl/aidl -h ./ -o ./ --lang=cpp libserviceaidl/aidl/com/test/IService.aidl

aidl -I ./libserviceaidl/aidl -h ./ -o ./ --lang=cpp libserviceaidl/aidl/com/test/IServiceCallback.aidl

  -I aidi 文件目录  -h头文件生成路径  -o cpp文件存放路径

2,Native service 差别不大

#define LOG_TAG "testservverfirst"
#include <log/log.h>#include <unistd.h>
#include <stdlib.h>
#include <utils/RefBase.h>
#include <utils/Log.h>
#include <binder/TextOutput.h>
#include <binder/IInterface.h>
#include <binder/IBinder.h>
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/IPCThreadState.h>
#include <termios.h> 
#include <utils/String16.h>
#include "com/test/BnService.h"
#include "com/test/BnServiceCallback.h"using namespace std;
using namespace android;class TestService : public com::test::BnService 
{public:TestService(){}binder::Status nativecall(int i) {ALOGI("server nativecall function is running %d",i);if(mycallback != nullptr){mycallback->onEventString(4,String16("callbacksuccuess"));}return binder::Status();}binder::Status  callMcu(int32_t file,const vector<uint8_t>& type, int32_t* _aidl_return){*_aidl_return = 1;ALOGI("server callMcu function is running _aidl_return",*_aidl_return);return binder::Status();}binder::Status  call(int32_t type){ALOGI("server call function is running call %d",type);return binder::Status();}// 实现回调注册binder::Status registerCallback(const sp<com::test::IServiceCallback>& callback){mycallback  = callback;return binder::Status();}private:sp<::com::test::IServiceCallback> mycallback;};int main(int argc, char const *argv[])
{ALOGD("Server is runing");defaultServiceManager()->addService(String16("TestService"), new TestService());ProcessState::self()->startThreadPool();IPCThreadState::self()->joinThreadPool();return 0;
}

C++ 调用前面有介绍,最后补充下java 的调用方式。

3,Java 调用

try {Class<?> clazz = Class.forName("android.os.ServiceManager");Method method = clazz.getMethod("getService",String.class);IBinder binder = (IBinder) method.invoke(null,"TestService");if (binder != null){IService iservice = IService.Stub.asInterface(binder);// 千万不要忘记注册iservice.registerCallback(mycallback);iservice.call(1);}
} catch (ClassNotFoundException | NoSuchMethodException e) {e.printStackTrace();
} catch (IllegalAccessException e) {e.printStackTrace();
} catch (InvocationTargetException e) {e.printStackTrace();
} catch (RemoteException e) {e.printStackTrace();
}

或者系统里面

 IService.Stub.asInterface(ServiceManager.getService("TestService"));

参考

[Android AIDL系列 1] 手动编译aidl文件,生成Java、C++[android]、C++[ndk]、Rust接口_aidl c++-CSDN博客

http://www.yayakq.cn/news/674063/

相关文章:

  • 广州南站在哪个区广告优化师面试
  • 做网站要注意哪些方面wordpress关于
  • 怎么计算网站开发费用沐众科技网站建设
  • 河北建网站建筑公司名称大全
  • 浙江做网站找谁素材库大全高清素材免费下载
  • 烟台网站建设科技公司河北邯郸区号
  • 适合ps做图的素材网站网站界面大小
  • 怎么用ps做网站首页个人淘宝客网站备案
  • 苏州最大的网站重庆中环建设有限公司网站
  • 济南网站设计价格济源制作网站
  • 青海省建设厅建管处网站百度官网入口链接
  • 南京网站建设公司排名京东云wordpress后台
  • 温州网站建设免费服务nas 支持做网站
  • 网站1g的空间能用多久赵县住房和城乡建设局网站
  • 沈阳网站建设建设公司百度浏览器app下载
  • 网站计算机培训机构哪个最好网站倍攻击
  • 平面在线设计网站长尾关键词排名推广
  • 网站的域名空间成都建设网页公司
  • 阿里云服务器建立网站国内交互网站
  • 高端集团官方网站建设公司天眼查 企业查询
  • 珠宝首饰网站建设规划书素材最多的网站
  • iis网站怎么做域名绑定58网站建设的目的
  • 谁能帮我做网站优化公司网站
  • 上海网站推广有哪些wordpress返回旧编辑器
  • 重庆网站策划搜索引擎营销案例有哪些
  • 网页游戏交易网站陕西因酷网站建设
  • 迪庆州住房和城乡建设局网站单页网站作用是什么
  • 青县建设银行网站找人代做网站需要注意什么
  • 货代新手怎么找客户同一个ip网站太多 seo
  • 建广告网站需要多少钱wordpress支持什么数据库