在android中发送图像到URL

发布于 2024-10-30 01:19:02 字数 1238 浏览 1 评论 0原文

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

   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 并且希望可以查看它在另一项活动中。

如何做到这一点请帮助我......

the following is the code which i am using to capture an image from the camera in my app

   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);
            }
        }
    }

after capturing the image and when i select insert it gets stored in memory but i want it to be sent to an URL and i want it to be viewed in another activity.

how to do this pls help me.....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧梦荧光笔 2024-11-06 01:19:02

您需要图像的 URL。

  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,

这对我有用。

You need the URL of the image.

  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();                        

        }  

You will be getting the URI in SelectedImageURI, then you can send that using Intent.putExtra();

This works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文