1

I'm using the android documentation:

training/camera/photobasics

and this is the code implementing:

public class CFoto extends AppCompatActivity {

    private ImageView img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cfoto);

        img = findViewById(R.id.imageView);

        if (ContextCompat.checkSelfPermission(CFoto.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(CFoto.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(CFoto.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 1000);
        }
    }

    //Create unic name
    String mCurrentPhotoPath;

    private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "Backup_" + timeStamp + "_";
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(imageFileName, ".jpg", storageDir);

        mCurrentPhotoPath = image.getAbsolutePath();
        return image;
    }

    //take foto
    static final int REQUEST_TAKE_PHOTO = 1;

    public void tomarFoto(View view) {
        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
            File photoFile = null;
            try {
                photoFile = createImageFile();
            } catch (IOException ex) {
            }
            if (photoFile != null) {
                Uri photoURI = FileProvider.getUriForFile(this, "com.example.android.fileprovider", photoFile);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI.toString());
                startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);

            }
        }
    }

    //preview image
    static final int REQUEST_IMAGE_CAPTURE = 1;

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            Bitmap imageBitmap = (Bitmap) extras.get("data");
            img.setImageBitmap(imageBitmap);
        }
    }
}

the camera is working and saves the photo locally What should I change to save the photo in a database? in the database I have assigned the longblob format for the image the database is remote

Benoit
  • 5,118
  • 2
  • 24
  • 43
Sandor
  • 41
  • 3
  • This is a very broad question - to effectively answer it, we need to know what you've already tried to do to save it to a database. https://stackoverflow.com/help/mcve refers in terms of what's a good question to get an answer. It may be that you need a tutorial on database connections from your application, in which case do that first, and ask any difficulties that you have with it here. – Withnail Nov 29 '18 at 14:42

1 Answers1

0

You can save the path of your photo in your database or convert it to base64 and then save it . I think this post can help you :Take picture and convert to Base64

Sofiane Majdoub
  • 826
  • 1
  • 9
  • 12