[java] view plain copy
- package
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- import
- public class MainActivity extends Activity implements
- private
- @Override
- protected void
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- uploadBtn = (Button) findViewById(R.id.main_btn);
- this);
- }
- @Override
- public void
- if
- final List<String> list = new
- "/storage/sdcard0/updateAdtech/orgpic/1.png");
- "/storage/sdcard0/updateAdtech/orgpic/2.png");
- new
- public void
- "just test", "sdcard/image/a.amr", list);
- };
- }.start();
- }
- }
- /**
- *
- * @Description: 上传方法
- *
- * @param audioPath
- * 上传音频文件地址 例:sdcard/image/a.amr
- *
- * @param text
- * 上传文本的值
- *
- * @param imageUrlList
- * 图片地址的集合 例:sdcard/image/a.jpg, sdcard/image/b.jpg
- *
- * @return void
- */
- private synchronized void
- List<String> imageUrlList) {
- try
- new
- int
- for (int i = 0; i < size; i++) {
- filePath[i] = imageUrlList.get(i);
- }
- // 链接超时,请求超时设置
- new
- 10 * 1000);
- 10 * 1000);
- // 请求参数设置
- new
- new
- "http://service.ireadhome.com/api/Upload/Image");
- new
- // 上传 文本, 转换编码为utf-8 其中"text" 为字段名,
- // 后边new StringBody(text,
- // Charset.forName(CHARSET))为参数值,其实就是正常的值转换成utf-8的编码格式
- "text",
- new StringBody(text, Charset.forName("UTF-8")));
- // 上传多个文本可以在此处添加上边代码,修改字段和值即可
- // 上传音频文件
- "audio",
- new FileBody(new File(audioPath), "audio/*"));
- // 上传图片
- for
- "fileimg", new FileBody(new File(p), "image/*"));
- }
- post.setEntity(entity);
- HttpResponse resp = client.execute(post);
- // 获取回调值
- "Response:"
- + EntityUtils.toString(resp.getEntity()));
- "StatusCode:"
- + resp.getStatusLine().getStatusCode());
- catch
- e.printStackTrace();
- }
- }
- }