WEB开发网
开发学院手机开发Android 开发 Android Post图片和数据 阅读

Android Post图片和数据

 2010-08-23 01:25:00 来源:WEB开发网   
核心提示:这几天一直在想Android中实现POST图片和POST数据的问题,今天终于写了一个小DOME给大家了!1 private void imageClient(){ 2 3 // // 隐藏title 4 // this.requestWindowFeature(Window.FEATURE_NO_TITLE); 5 /

这几天一直在想Android中实现POST图片和POST数据的问题,今天终于写了一个小DOME给大家了!

1 private void imageClient(){ 2 3 // // 隐藏title 4 // this.requestWindowFeature(Window.FEATURE_NO_TITLE); 5 // 6 // // 设置全屏 7 // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 8 fileName = UUID.randomUUID().toString(); 9 10 try{11 Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);12 imgFile = new File(Environment.getExternalStorageDirectory(), fileName + ".jpg");13 Uri outputFileUri = Uri.fromFile(imgFile);14 cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);15 startActivityForResult(cameraIntent, 10);16 } catch (Exception ex) {17 ex.printStackTrace();18 Log.e("EP", "" + ex.getMessage());19 }20 }21 22 @Override23 protected void onActivityResult(int requestCode, int resultCode, Intent data){24 // 父类方法25 super.onActivityResult(requestCode, resultCode, data);26 27 switch (resultCode) {28 case RESULT_OK:29 LogUtil.info("on Activity Result");30 Bundle extras = data.getExtras();31 b = (Bitmap) extras.get("data");32 33 new Thread(new Runnable(){34 public void run(){35 if (b != null) {36 try {37 BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + "/test.jpg"));38 // 压缩图片39 b.compress(CompressFormat.JPEG, 75, bos);40 bos.flush();41 bos.close();42 } catch (Exception e) {43 Log.e("Exception", "file or compress exception");44 e.printStackTrace();45 }46 47 }48 imgFile = new File(android.os.Environment.getExternalStorageDirectory() + "/" +fileName + ".jpg");49 50 // ImgManager.resize(file, file, 200, "jpg");51 52 // 发送到服务器53 if(!HttpUtil.postImg("http://neil.finalist.hk/namex/namex/nclient/upload", "user", "client", imgFile)){54 // 发送失败则重发一次55 HttpUtil.postImg("http://neil.finalist.hk/namex/namex/nclient/upload", "user", "client", imgFile);56 }57 }58 }).start();59 }60 }

1 2  下一页

Tags:Android Post 图片

编辑录入:coldstar [复制链接] [打 印]
赞助商链接