将图像发送到android中的URL

时间:2011-04-05 11:42:10

标签: android url camera

以下是我用于从我的应用程序中的相机捕获图像的代码

   public void startCamera() 
    {
        Log.d("ANDRO_CAMERA", "Starting camera on the phone...");
        String fileName = "testphoto.jpg";
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, fileName);
        values.put(MediaStore.Images.Media.DESCRIPTION,"Image capture by camera");
        values.put(MediaStore.Images.Media.MIME_TYPE, "image/jpeg");

        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        startActivityForResult(intent, IMAGE_CAPTURE);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == IMAGE_CAPTURE) 
        {
            if (resultCode == RESULT_OK)
            {
                Log.d("ANDRO_CAMERA","Picture taken!!!");
                imageView.setImageURI(imageUri);
            }
        }
    }

捕获图像后,当我选择插入时,它会存储在内存中,但我希望将其发送到URL,我希望在另一个活动中查看它。

怎么做这个请帮帮我.....

1 个答案:

答案 0 :(得分:2)

您需要图片的网址。

  public void startCamera(){
   Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);  
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  
  }

   Uri selectedImageUri;
   private static final int CAMERA_PIC_REQUEST = 1337; 
   @Override
public void onActivityResult(int requestCode, int resultCode, Intent intent){
        if (requestCode == CAMERA_PIC_REQUEST) { 
            selectedImageUri = Intent.getData();                        

        }  

您将在SelectedImageURI中获取URI,然后您可以使用Intent.putExtra();

发送该URI

这适合我。