下载/上传的Andr​​oid Ksoap2 Web服务 [英] Android Ksoap2 web service for download/Upload

查看:333
本文介绍了下载/上传的Andr​​oid Ksoap2 Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写使用 KSOAP Web服务程序和文件从Web服务下载到Android手机。我必须从Web服务访问一个文本文件,并下载在Android mobile.Can有人帮我补习或联系相应的IT

解决方案

KSOAP 是简单地发送请求并获得响应。举例地段有没有在网上搜索,让你的合适的例子。下面一些例子 例1

<一个href="http://www.android10.org/index.php/articleslibraries/167-using-ksoap2-for-android-soap-web-service">Example 2

例3

例4

有关通过SOAP Web服务上载和下载的文件我用下面的方法

上传

  1. 您的文本文件转换为二进制字符串
  2. 在其存储到一个字符串
  3. 通过SOAP Web服务发送

示例

 乌里uriString中= Uri.parse(objBundle.get()的toString());
档案文件=新的文件(uriString.getPath());
的FileInputStream objFileIS;
objFileIS =新的FileInputStream(文件);
ByteArrayOutputStream objByteArrayOS =新ByteArrayOutputStream();
byte []的byteBufferString =新的字节[1024];
对于(INT readNum;(readNum = objFileIS.read(byteBufferString))= -1;!)
{
objByteArrayOS.write(byteBufferString,0,readNum);
的System.out.println(读+ readNum +字节);
}
byte []的byteBinaryData = Base64.en code((objByteArrayOS.toByteArray()),Base64.DEFAULT);
strAttachment codeD =新的String(byteBinaryData);
 

下载:

  1. 要求服务器端开发人员发送文件二进制字符串的格式
  2. 获取响应字符串,并将其转换为一个文件,并将其存储在SD卡。

示例

 字节[]字节;
strBinaryPDFString = cursorGetBinaryString.getString(0);在表的二进制串的索引//位置
文件的CreateFile =新的文件(Environment.getExternalStorageDirectory()/文件夹/);
createfile.mkdirs();
文件OUTPUTFILE =新的文件(的CreateFile,FileName.pdf); //创建于手机内存中的临时文件
新的FileOutputStream(OUTPUTFILE);
字节= Base64.de code(strBinaryPDFString,Base64.DEFAULT);
文件的文件路径=新的文件(Environment.getExternalStorageDirectory()/文件夹/ FileName.pdf);
的OutputStream pdffos =新的FileOutputStream(文件路径);
pdffos.write(字节); //写二进制串入payslip.pdf临时文件
pdffos.flush();
pdffos.close();
 

以上方法工作对我罚款。可能是你可以找到另一种最好的方法。

I want to write a program using ksoap web service and download a file to android mobile from web service. I must access a text file from web service and download it in the android mobile.Can some one help me with tutorial or links corresponding it

解决方案

KSOAP is simply send request and getting responds. Lot of example are there in web search and get your suitable example. Here some examples Example 1

Example 2

Example 3

Example 4

For uploading and downloading the files through the SOAP web service I'm using the following method

Uploading:

  1. Convert your text file to Binary String
  2. Store it into the single string
  3. send it through the soap web service

Example

Uri uriString = Uri.parse(objBundle.get("").toString());
File file = new File(uriString.getPath());
FileInputStream objFileIS;
objFileIS = new FileInputStream(file);
ByteArrayOutputStream objByteArrayOS = new ByteArrayOutputStream();
byte[] byteBufferString = new byte[1024];
for (int readNum; (readNum = objFileIS.read(byteBufferString)) != -1;) 
{
objByteArrayOS.write(byteBufferString, 0, readNum);
system.out.println("read " + readNum + " bytes,");
}                    
byte[] byteBinaryData = Base64.encode((objByteArrayOS.toByteArray()), Base64.DEFAULT);
strAttachmentCoded = new String(byteBinaryData);

Download:

  1. Ask the server side developers to send the your file in the format of binary string
  2. Get the responds string and convert it as a file and store it in sdcard.

Example

byte[] bytes;
strBinaryPDFString = cursorGetBinaryString.getString(0);//Index position of the binary string in table
File createfile = new File(Environment.getExternalStorageDirectory(),"/Folder/");
createfile.mkdirs();
File outputFile = new File(createfile,"FileName.pdf");//creating temporary file in phone Memory
new FileOutputStream(outputFile);
bytes = Base64.decode(strBinaryPDFString,Base64.DEFAULT);
File filepath = new File(Environment.getExternalStorageDirectory(),"/Folder/FileName.pdf");
OutputStream pdffos = new FileOutputStream(filepath);
pdffos.write(bytes);//writing the binary string into the payslip.pdf temporary file
pdffos.flush();
pdffos.close();

The above method is working fine for me. May be you can find another best method.

这篇关于下载/上传的Andr​​oid Ksoap2 Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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