调用照相
private void imageClient(){        //        // 隐藏title//        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//    //        // 设置全屏//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);        fileName = UUID.randomUUID().toString();        try{            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);            imgFile = new File(Environment.getExternalStorageDirectory(), fileName + ".jpg");            Uri outputFileUri = Uri.fromFile(imgFile);            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);            startActivityForResult(cameraIntent, 10);        } catch (Exception ex) {            ex.printStackTrace();            Log.e("EP", "" + ex.getMessage());        }    }        @Override    protected void onActivityResult(int requestCode, int resultCode, Intent data){        // 父类方法        super.onActivityResult(requestCode, resultCode, data);                switch (resultCode) {            case RESULT_OK:                LogUtil.info("on Activity Result");                Bundle extras = data.getExtras();                b = (Bitmap) extras.get("data");                                new Thread(new Runnable(){                    public void run(){                        if (b != null) {                            try {                                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(android.os.Environment.getExternalStorageDirectory() + "/test.jpg"));                                // 压缩图片                                b.compress(CompressFormat.JPEG, 75, bos);                                bos.flush();                                bos.close();                            } catch (Exception e) {                                Log.e("Exception", "file or compress exception");                                e.printStackTrace();                            }                                    }                        imgFile = new File(android.os.Environment.getExternalStorageDirectory() + "/" +fileName + ".jpg");                                                // ImgManager.resize(file, file, 200, "jpg");                                                // 发送到服务器                        if(!HttpUtil.postImg("http://neil.finalist.hk/namex/namex/nclient/upload", "user", "client", imgFile)){                            // 发送失败则重发一次                            HttpUtil.postImg("http://neil.finalist.hk/namex/namex/nclient/upload", "user", "client", imgFile);                        }                    }            }).start();        }    }

发送
@SuppressWarnings("deprecation")    public static boolean postImg(String url, String u, String c, File file){        LogUtil.info("" + file.exists());                PostMethod postMethod = new PostMethod(url);                Part[] part = new Part[4];        part[0] = new StringPart("u", u);        part[1] = new StringPart("c", c);        try {            part[2] = new FilePart("Filedata", file);        } catch (FileNotFoundException ex) {            ex.printStackTrace();            Log.e("file exception", ex.getMessage());        }        part[3] = new StringPart("flag", "image");                MultipartRequestEntity mrp = new MultipartRequestEntity(part, postMethod.getParams());        postMethod.setRequestEntity(mrp);        org.apache.commons.httpclient.HttpClient client = new org.apache.commons.httpclient.HttpClient();        client.getParams().setContentCharset("utf-8");        try {            client.executeMethod(postMethod);            if("false".equals(postMethod.getRequestEntity().toString())){                return false;            }        } catch (HttpException e) {            e.printStackTrace();            return false;        } catch (IOException e) {            e.printStackTrace();            return false;        }finally {            if (client != null) {                client = null;            }            if (postMethod != null) {                postMethod = null;            }        }        return true;    }    

更多相关文章

  1. Android(安卓)Wifi模块分析(三)
  2. Android中dispatchDraw分析
  3. Android四大基本组件介绍与生命周期
  4. Android(安卓)Service AIDL
  5. Android(安卓)bluetooth介绍(四): a2dp connect流程分析
  6. Android调用天气预报的WebService简单例子
  7. android打电话发短信
  8. android 拨打紧急号码,通话时开启免提功能实现
  9. Android调用.NET Webservice报org.ksoap2.serialization.SoapPri

随机推荐

  1. Android键盘操作响应
  2. android山寨暴风影音UI
  3. Android中如何让TextView显示指定的行数
  4. android 更加复杂的小鱼游
  5. Android监听音量变化
  6. Android中TabHost的使用
  7. Android Framework---themes.xml
  8. android之SQlite创建数据库操作
  9. ListView、ScrollView、GridView等去除滑
  10. Android:获取状态栏高度