Giter Club home page Giter Club logo

aidl-transfer-image-example's Introduction

AIDL-transfer-Byte-example

本例子利用AIDL实现了进程间图片的传输。基本流程是:client端发送请求,server端下载byte类型的数据并通过接口函数回传。 由于底层是通过传输byte实现的,因此该例子还可以扩展为传输其他可与byte互相转换的复杂类型。由于Server与Client端之间仅靠.aidl文件进行通信,因此Server端如何进行下载对Client端没有影响。AIDL即体现出了interface的作用。

###环境 Mac OS X
Android Studio 1.5

###基本原理

  1. 整个工程含两个module,一个是client端(即app),另一个是server端。

  2. server端实质上是定义并注册了一个service类。系统内所有其他进程皆可调用该服务进行下载。

  3. 调用的具体方法是给出所要下载文件的url,赋值给client端的urlString变量,然后绑定服务即可。

###使用方法 首先运行aidlserver这个module(开启服务),然后运行app(调用服务),界面加载完毕后即可看到下载好的图片。

###注意
受限于Android本身对AIDL的设计,利用AIDL传输的数据大小不得大于1MB,否则会报TransactionTooLargeException,目前代码里暂时没有考虑该问题的解决方案。
--update--
2016-03-05
问题已解决,方法为对每个较大的请求拆分成若干个小于1MB的Request,然后依次调用server端进行传输,将结果放到一个大的byte缓冲区进行拼接恢复即可。因此现在传输的图片大小可以大于1MB,工程中所给的url链接指向的图片大小为3.1MB,测试通过。

aidl-transfer-image-example's People

Contributors

ymjiang avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

zhaozhenye

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.