Android上的Thrift客户端 [英] Thrift client on Android

查看:276
本文介绍了Android上的Thrift客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android开发的新手,想要创建一个使用thrift客户端的应用程序,它在网络上使用节俭的服务器。我已经得到了thrift定义文件和由thrift编译器生成的java代码。

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 java code generated by the thrift compiler.


  1. 我需要如何启动?如何将节俭库添加到我的项目?我需要自己编译,如果是,我应该如何完成这一点,以便与android兼容?

  1. How do I need to start? How do I add the thrift library to my project? Do I need to compile it myself and if yes how should I accomplish this to be android compatible?

我可以直接使用自动生成的函数类似于这个

Can I directly use the auto generated functions similar to this

public void getProduct(int productID, org.apache.thrift.async.AsyncMethodCallback resultHandler)

对我的服务进行异步调用,以便我遵循android最佳做法?或者使用此功能阻止我的应用程序以任何方式或有另一种方式在Android上优先于此?

to make asynchronous calls to my service so that I follow the android best practices? Or does using this function block my application in any way or is there another way to be preferred over this on android?

我使用目前版本的谷歌ADT(eclipse)。我的应用程序需要运行在Android 4+设备上(我将minSdkVersion设置为 15 )。

I use the current version of googles ADT (eclipse). My app needs to run just on android 4+ devices (I set the minSdkVersion to 15).

推荐答案


  1. 是的,您需要自己构建Android的thrift-lib。 Android有它自己的httpcore,没有消费方法。在这里你可以找到如何改变节俭库:

  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.

示例

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);


您需要将其作为Android AsyncTask执行: AsyncTask | Android开发人员

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

这篇关于Android上的Thrift客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆