在Android节俭客户端 [英] Thrift client on Android

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

问题描述

我是新来的android的发展,并希望创建与使用旧货服务器我的网络上的节俭客户端的应用程序。我已经得到了节俭的定义文件,并通过节俭编译器生成的Java code。

  1. 我如何需要开始?我如何节俭库添加到我的项目?我需要编译它自己,如果是我应该如何做到这一点是android的兼容?

  2. 我可以直接使用自动生成的功能,类似于这样

     公共无效getProduct(INT的productID,org.apache.thrift.async.AsyncMethodCallback resultHandler)
     

    进行异步调用我的服务让我跟着Android的最佳做法?还是利用这个功能阻止我的应用程序以任何方式或是否有另一种方式是pferred在这个在Android $ P $?

我用谷歌的最新版本ADT(日蚀)。我的应用程序需要只在Android 4+设备上运行(我设置的minSdkVersion为 15 )。

解决方案
  1. 是的,你需要自己建立节俭LIB为Android。 Android有它自己的HttpCore不具有一个消耗-方法。在这里你可以找到如何改变节俭库:<一href="http://grokbase.com/t/thrift/commits/12cpyd071g/git-commit-thrift-1641-thrift-0-8-not-compatible-with-android-httpclient-patch-darin-tay"相对=nofollow title="http://grokbase.com/t/thrift/commits/12cpyd071g/git-commit-thrift-1641-thrift-0-8-not-compatible-with-android-httpclient-patch-darin-tay">here指令 之后,刚刚的jar文件添加到库文件夹并将其添加到构建路径。

  2. 例如

      THttpClient hclient =新THttpClient(你的/终端/ URL);
    TProtocol协议=新TBinaryProtocol(hclient); //它取决于你的数据格式
    Service.Client客户端=新Service.Client(协议);
    产品产品= client.getProduct(INT的productID);
     

您需要执行它作为一个Android的AsyncTask:的AsyncTask | Android开发者

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. 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?

  2. Can I directly use the auto generated functions similar to this

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

    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?

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. 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

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

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