I am creating an Android app which calls the built-in camera to capture a video and then display it in a preview.
This is the code.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vid1 = (VideoView) findViewById(R.id.videoView);
btn1 = (Button) findViewById(R.id.button);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i1 = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if(i1.resolveActivity(getPackageManager()) != null) {
startActivityForResult(i1, 123);
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
if(requestCode == 123 && resultCode == RESULT_OK) {
Log.d("hi", data.getData().getPath());
Uri myvideolink = data.getData();
vid1.setVideoURI(myvideolink);
}
}
What is happening is, the data.getData()
is giving me a path from external storage whereas the video is saved in the internal storage, DCIM folder. That is, the log statement,
Log.d("hi", data.getData().getPath());
is giving me this
/hi: /external/video/media/162872
So,
- How do I avoid this and get the right path so that the video is displayed in the preview?
- Is there any commands/libraries using which I can retrieve the path of the most recent video captured from the internal storage, DCIM? (I need this because after displaying preview, I also need to send it to a server)