【问题标题】:Camara or Gallery Button to upload selected photo用于上传所选照片的​​相机或图库按钮
【发布时间】:2014-02-15 19:36:38
【问题描述】:

我想将照片上传到我的服务器。 相机的代码完美运行,但是当我实现从图库中选择图像的新按钮时不起作用。

foto 是一个字符串,我在其中放置要上传到服务器的文件名。

我已经实现了两个按钮相机和画廊:

public void onClick(View v) {

    switch (v.getId()) {
        case R.id.button1:
            TAKE_PICTURE = 1;
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            Uri output = Uri.fromFile(new File(foto));
            intent.putExtra(MediaStore.EXTRA_OUTPUT, output);

            startActivityForResult(intent, TAKE_PICTURE); 
            break;

        case R.id.btGallery:

            Intent i = new Intent(
            Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

            Uri output1 = Uri.fromFile(new File(foto2));
            i.putExtra(MediaStore.EXTRA_OUTPUT, output1);

            startActivityForResult(i, 2);

            break;
    }
}

camara 按钮和动作起作用并将图像上传到服务器。

onActivityResult 函数是:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    ImageView iv = (ImageView) findViewById(R.id.imageView1);

    switch(requestCode) {

        case 1:
            iv.setImageBitmap(BitmapFactory.decodeFile(foto));
            File file = new File(foto);

            if (file.exists()) {
                UploaderFoto nuevaTarea = new UploaderFoto();
                nuevaTarea.execute(foto);
            }
            else
                Toast.makeText(getApplicationContext(), "No se ha realizado la foto", Toast.LENGTH_SHORT).show();

                break;

        case 2:
            File file2 = new File(foto2);
            if (file2.exists()) {
                UploaderFoto nuevaTarea = new UploaderFoto();
                nuevaTarea.execute(foto2);
                Toast.makeText(getApplicationContext(), "DENTRO EXISTS GALLERY", Toast.LENGTH_SHORT).show();
            }
            else
                Toast.makeText(getApplicationContext(), "FUERA EXISTS", Toast.LENGTH_SHORT).show();

                break;

    }

}

在 ActivityResult 中进入 if 循环并显示 Toast,但从不将信息传递给 UploaderPhoto。

谢谢

【问题讨论】:

    标签: php android button android-camera android-gallery


    【解决方案1】:

    如果你想使用 HTML5 和设备的摄像头,有一个 HTML5 功能可以做到这一点。示例:

    <input type="file" accept="image/*" capture="camera" />
    

    从这里:https://coderwall.com/p/epwmoa

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-08
      • 2016-12-27
      • 2013-11-23
      • 2019-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多