Share mp4 file generated by my app to social networks. share intent

0

I need to share my mp4 video file generated by my app, which acquires name with a ( System.currentTimeMillis /1000 ). the share action must choose that last generated file to share it in social networks.

I leave the initRecorder method which generates the mp4 file and the current compartir method.

private final String MAIN_FOLDER = "DCApp/";

private final String RUTA_VIDEO = MAIN_FOLDER + "DCvideos";

private void initRecorder(){

        String videoName = "DC_" + (System.currentTimeMillis() / 1000) + ".mp4";
        File fileVideo = new File(Environment.getExternalStorageDirectory(), VIDEO_RUTE);

        try{

            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
            mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
            mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            mMediaRecorder.setOutputFile(fileVideo + videoName);
            mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
            mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
            mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
            mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
            mMediaRecorder.setVideoFrameRate(30);
            int rotation = getWindowManager().getDefaultDisplay().getRotation();
            int orientation = ORIENTATIONS.get(rotation + 90);
            mMediaRecorder.setOrientationHint(orientation);
            mMediaRecorder.prepare();

        }catch(IOException e){
            e.printStackTrace();
        }

    }

Share method:

 private void share() {

    Intent share = new Intent(android.content.Intent.ACTION_SEND);
    share.putExtra(Intent.ACTION_PICK, MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
    share.setType("video/");
    startActivity(Intent.createChooser(share, "share via:"));
}
    
asked by J. Sanchez 22.05.2018 в 21:06
source

1 answer

-1

Taking into account the comments and what you asked me, plus some official documentation read, I would take the following path:

private void share(String videoName ) {

        Intent share = new Intent(android.content.Intent.ACTION_SEND);
        share.setType("video/mp4"); // Configuras el tipo de archivo

        // Tomas el archivo desde la ruta de guardado, para que no haya error
        File fileToShare = new File(RUTA_VIDEO + videoName ); 
        Uri uri = Uri.fromFile(fileToShare);

        //Agregas la uri del video que deseas enviar, esto se puede usar para cualquier archivo.
        share.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(share, "Compartilo!"));
}
  

You should send the file name as a parameter.

    
answered by 22.05.2018 в 21:41