使用 Android快速开发框架 Afinal 0.3 快速开发网络应用相关APK
16lz
2022-01-08
这里介绍了android快速开发框架afinal0.3的http操作模块 FinalHttp,希望能对你们有所帮助。
afinal 网址:
https://github.com/yangfuhai/afinal
http://code.google.com/p/afinal/
普通的get操作:
- FinalHttpfh=newFinalHttp();
- fh.get("http://www.yangfuhai.com",newAjaxCallBack<String>(){
- @Override
- publicvoidonLoading(longcount,longcurrent){//每1秒钟自动被回调一次
- textView.setText(current+"/"+count);
- }
- @Override
- publicvoidonSuccess(Stringt){
- textView.setText(t==null?"null":t);
- }
- @Override
- publicvoidonStart(){
- //开始http请求的时候回调
- }
- @Override
- publicvoidonFailure(Throwablet,StringstrMsg){
- //加载失败的时候回调
- }
- });
- FinalHttpfh=newFinalHttp();
- fh.get("http://www.yangfuhai.com",newAjaxCallBack<String>(){
- @Override
- publicvoidonLoading(longcount,longcurrent){//每5秒钟自动被回调一次,通过progress是否回调onLoading和回调频率
- textView.setText(current+"/"+count);
- }
- @Override
- publicvoidonSuccess(Stringt){
- textView.setText(t==null?"null":t);
- }
- }.progress(true,5));//通过这里设置onloading的频率
- AjaxParamsparams=newAjaxParams();
- params.put("username","michaelyang");
- params.put("password","123456");
- params.put("email","test@tsz.net");
- params.put("profile_picture",newFile("/mnt/sdcard/pic.jpg"));//上传文件
- params.put("profile_picture2",inputStream);//上传数据流
- params.put("profile_picture3",newByteArrayInputStream(bytes));//提交字节流
- FinalHttpfh=newFinalHttp();
- fh.post("http://www.yangfuhai.com",params,newAjaxCallBack<String>(){
- @Override
- publicvoidonLoading(longcount,longcurrent){
- textView.setText(current+"/"+count);
- }
- @Override
- publicvoidonSuccess(Stringt){
- textView.setText(t==null?"null":t);
- }
- });
android文件下载:
- FinalHttpfh=newFinalHttp();
- fh.download("http://www.xxx.com/下载路径/xxx.apk","/mnt/sdcard/testapk.apk",newAjaxCallBack<File>(){
- @Override
- publicvoidonLoading(longcount,longcurrent){
- textView.setText("下载进度:"+current+"/"+count);
- }
- @Override
- publicvoidonSuccess(Filet){
- textView.setText(t==null?"null":t.getAbsoluteFile().toString());
- }
- });
http cookie操作:
- BasicClientCookiebcc=newBasicClientCookie("","");
- bcc.setDomain("yangfuhai.com");
- bcc.setPath("/");
- bcc.setVersion(1);
- PreferencesCookieStorepcs=newPreferencesCookieStore(this);
- pcs.addCookie(bcc);
- FinalHttpfh=newFinalHttp();
- hk.setCookieStore(pcs);
- fh.post("http://www.yangfuhai.com",newAjaxCallBack<String>(){
- @Override
- publicvoidonLoading(longcount,longcurrent){
- textView.setText(current+"/"+count);
- }
- @Override
- publicvoidonSuccess(Stringt){
- textView.setText(t==null?"null":t);
- }
- });
亲,是不是有了这个框架,你就可以减少至少一半的代码呢?
更多相关文章
- Unknown host ‘XXXX: nodename nor servname provided, or not
- Android利用DownloadManager实现文件下载
- Github android客户端源代码分析之一:环境搭建
- android 三种定位方式
- Android(安卓)判断网络状态,并且在没有网络的时候,打开网络设置对
- Android(安卓)-- 多线程下载
- Android源码下载并绑定到Eclipse中
- Android(安卓)Studio 查看不到SDK源码解决办法
- Android利用DownloadManager实现文件下载