Thrift client on Android

前端 未结 2 1840
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 08:25

I\'m new to android development and want to create an app with a thrift client which is using a thrift server on my network. I already got the thrift definition file and the

2条回答
  •  梦谈多话
    2021-01-03 09:15

    1. yes, you need to build the thrift-lib for Android by yourself. Android has it's own httpcore that doesn't have a consume-method. here you can find how to change the thrift-library: here instruction After that just add the jar-file to the libs-folder and add it to the build-path.

    2. example

      THttpClient hclient = new THttpClient("your/endpoint/url");
      TProtocol protocol = new TBinaryProtocol(hclient); // it depends on your data-format
      Service.Client client = new Service.Client(protocol);
      Product product = client.getProduct(int productID);
      

    you need to execute it as an Android AsyncTask: AsyncTask | Android Developers

提交回复
热议问题