Search code examples
androidxmlparse-platformandroid-camera-intent

I cant find the Video Path for capturing video


at the moment i have some process done and i could show you. The purpose is to record a video and save it into the back4app database.

Error description

This will come from this...

This code will start the recording

Then i will show you my xml/provider... How is created

And the file...

The file

Please take into consideration i am also adding pictures succesfully in the same fragment i dont know if i change something from this files i will have any problem with pictures.

This is how i create the file....

private File getFilePath(){
    File folder=new File("sdCard/test_drives");
    if(!folder.exists()){
        folder.mkdir();
    }

    Date currentTime = Calendar.getInstance().getTime();

    video_file=new File(folder,"test_drives_"+currentTime+".mp4");
    return video_file;
}

This is my onActivityForResult method....

public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode==VIDEO_REQUEST && resultCode==RESULT_OK){
        ParseQuery<ParseObject> query= ParseQuery.getQuery("CitaTestDrive");
        query.getInBackground(idEventoTestDrive, new GetCallback<ParseObject>() {
            @Override
            public void done(ParseObject object, ParseException e) {
                videoUri=data.getData();
                String file=videoUri.getPath();
              File inputFile = new File(file);

                try {
                    fileInputStream = new FileInputStream(inputFile);
                } catch (FileNotFoundException ex) {
                    ex.printStackTrace();
                }
                Bitmap thumbnailBm = BitmapFactory.decodeStream(fileInputStream);
                ByteArrayOutputStream st = new ByteArrayOutputStream();
                thumbnailBm.compress(Bitmap.CompressFormat.JPEG, 50, st);
                byte[] byteArr = st.toByteArray();
                Date currentTime = Calendar.getInstance().getTime();

                ParseFile thumbFile = new ParseFile("TestDrive"+" "+currentTime+" "+nombreAsesor+".jpg", byteArr);
                object.put("Video",thumbFile);
                object.saveInBackground(new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if(e==null){
                            Toast.makeText(getActivity(),"Video uploaded to server",Toast.LENGTH_LONG).show();
                        }else{
                            Toast.makeText(getActivity(),e.toString(),Toast.LENGTH_LONG).show();
                        }
                    }
                });

Remember that this is in a Fragment!

if you need anything else i will be here to provide to you more info i will attack the way i get the pictures...

 if (requestCode == REQUEST_IMAGE_SUBIR_CEDULA && resultCode == RESULT_OK) {
        if (data != null && data.getExtras() != null) {
            bitmap = (Bitmap) data.getExtras().get("data");
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byte[] byteArray = stream.toByteArray();
            ParseFile file = new ParseFile("image.jpg", byteArray);

            imagenSubirCedula.setImageBitmap(bitmap);

        }
    }

Solution

  • This is how i create the file....

    Never hardcode paths.

    The documentation for FileProvider has this for the explanation of <external-path>:

    Represents files in the root of the external storage area. The root path of this subdirectory is the same as the value returned by Environment.getExternalStorageDirectory().

    So, you would need to replace:

    File folder=new File("sdCard/test_drives");
    

    with:

    File folder=new File(Environment.getExternalStorageDirectory(), "test_drives");
    

    Note, though, that you cannot use Environment.getExternalStorageDirectory() on Android 10 and higher devices. So, you will need to do something else if you intend for this app to be distributed publicly, as some of your users may be running Android 10 and higher. For example, you could switch your FileProvider metadata to use <external-files-path>, then use:

    File folder=new File(context.getExternalFilesDir(null), "test_drives");
    

    ...where context is a Context (e.g., an activity).