Get Extras from video - android

I have been trying to get a list of the extras bundled with the native camera app
I want to take a video, save it and then keep the file path
Intent chooseCamera = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(chooseCamera,cameraData);
Ive got this so far and I found a tutorial on getting the bitmap for a still image but not the video. Any ideas ?

use this :
cameraData=2;
Intent chooseCamera = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(chooseCamera, cameraData);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
try{
if(resultCode==Activity.RESULT_OK){
if(requestCode==cameraData){
path = data.getData().toString(); //VIDEO path
}
}
}catch(Exception e){
e.printStackTrace();
}
}

Related

How to get name of captured image in android onActivityResult

how to get image name from captured image/intent data. any one suggest me. i need through intent data only
Here is my code:
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, PIC_FROM_CAMERA);
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK && data != null){
Bitmap photo = (Bitmap) data.getExtras().get("data");
}
}
AS from the Android documentation here you could not get any name for your image since android wont name for your file but you could get the time when the image was taken and the dimension of the image from This answer You could name the image by yourself and send that bitmap.

Android Training: Capturing Photo example

I'm quite new to android but have been working through the examples on google's site - I'm on this one: http://developer.android.com/training/camera/index.html
This is a "simple" example on using the camera function on android. There is a button that calls up an intent. The intent is displayed below.
private void dispatchTakePictureIntent(int actionCode) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
switch(actionCode) {
case ACTION_TAKE_PHOTO_B:
File f = null;
try {
f = setUpPhotoFile();
mCurrentPhotoPath = f.getAbsolutePath();
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
} catch (IOException e) {
e.printStackTrace();
f = null;
mCurrentPhotoPath = null;
}
break;
default:
break;
} // switch
startActivityForResult(takePictureIntent, actionCode);
As you can see above, the intent putExtra of key MediaStore.EXTRA_OUTPUT. On android's website: http://developer.android.com/reference/android/provider/MediaStore.html#EXTRA_OUTPUT it says that the MediaStore.EXTRA_OUTPUT has a constant value of "output".
Once the user clicks on a button, the intent is called and the following is an extract of the onActivityResult method given in the code:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case ACTION_TAKE_PHOTO_S: {
if (resultCode == RESULT_OK) {
handleSmallCameraPhoto(data);
}
break;
} // ACTION_TAKE_PHOTO_S
A method handleSmallCameraPhoto(data); is then called. Here is the code for handleSmallCameraPhoto.
private void handleSmallCameraPhoto(Intent intent) {
Bundle extras = intent.getExtras();
mImageBitmap = (Bitmap) extras.get("data");
mImageView.setImageBitmap(mImageBitmap);
mVideoUri = null;
mImageView.setVisibility(View.VISIBLE);
mVideoView.setVisibility(View.INVISIBLE);
}
Now in the above method, we want to getExtras from the intent - so what was putExtra in under method dispatchTakePictureIntent we are extracting.
We see this line here.
mImageBitmap = (Bitmap) extras.get("data");
Isn't the "data" inside extras.get("data") a key for android to extract the extra data for? From dispatchTakePictureIntent, the key was MediaStore.EXTRA_OUTPUT which had a constant of "output" not "data", how does android know what is associated with "data"?
Ok. I actually found the answer on the android website. The answer is here: http://developer.android.com/training/camera/photobasics.html#TaskPath under the heading "Get the Thumbnail"
This is a special case and android saves thumbnails with the key called "data" in the intent.
The site says: This thumbnail image from "data" might be good for an icon, but not a lot more.

Get embedded cover art from a mp3 file

I've been searching in this page how to get the covert art from a mp3 file.
I'm developing one music app and I want to get the cover art of the song that is inside the mp3 file (ID3v2 tag). But, I have search a lot but I haven't found how can I do it.
Somebody know how to do it?
Thanks everyone.
Here is my implementation of how I get the cover art. First I select an audio file:
MediaMetadataRetriever myRetriever = new MediaMetadataRetriever();
Uri selectedAudio;
//...
//on button click or any other event
Intent intent = new Intent();
String chooser = "Select audio file";
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, chooser), GET_AUDIO_CODE);
Then in onActivityResult i get the URI of the file:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
{
selectedAudio = data.getData();
MediaMetadataRetriever myRetriever = new MediaMetadataRetriever();
myRetriever.setDataSource(this, selectedAudio); // the URI of audio file
setArtwork(myRetriever);
}
//...
}
And after that I set the cover art:
//....
public boolean setArtwork(MediaMetadataRetriever myRetriever)
{
byte[] artwork;
artwork = myRetriever.getEmbeddedPicture();
if (artwork != null)
{
Bitmap bMap = BitmapFactory.decodeByteArray(artwork, 0, artwork.length);
ivArtwork.setImageBitmap(bMap);
return true;
}
else
{
ivArtwork.setImageBitmap(null);
return false;
}
}

Android File Chooser Absolute Path Issue

I use the intent filter to get the path of the file selected by the user with a file-chooser,
unfortunately I have problem to obtain the absolute path,
the path onActivityResult starts always with various extra data that cause errors in my app
for example
/content/:/myabsolutepath
or
file:///myabsolutepath
and the extra attributes depends on file type, file manager on the phone etc.
I need to get only the absolute path in the form
/myabsolutepath
Here there is my code
private void openFile() {
Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.setType("file/*");
startActivityForResult(i, FILE_REQ_CODE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent i) {
//String with the path;
path = i.getDataString();
super.onActivityResult(requestCode, resultCode, i);
}
Try:
path = i.getData().getPath();

take picture from android camera and send it to web server

im build some apps that call camera activity..
im just to take picture from my apps and send it to web server..
but i can't get my image path..
im always getting NullException Error when try to get image path..
here's my code when calling camera activity :
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
this.startActivityForResult(camera, PICTURE_RESULT);
and this is code for activity result :
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICTURE_RESULT){
if (resultCode == Activity.RESULT_OK) {
takePicture(data);
} else if (resultCode == Activity.RESULT_CANCELED) {
}
}
}
protected void takePicture(Intent data) {
Bundle b = data.getExtras();
pic = (Bitmap) b.get("data");
if (pic != null) {
imagePicture.setImageBitmap(pic);
}
}
is there something wrong with my code?
Thanks
Ok, I see your problem. You're not setting the path to begin with. Please look at this doc.
http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE
So you see, when you call ACTION_IMAGE_CAPTURE you are not passing it the extra EXTRA_OUTPUT that tells the application where the picture is going to be stored. This EXTRA_OUTPUT is the path to the file.
So right under where you make the intent do this:
Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
URI pictureUri = Uri.fromFile(new File(<path to your file>));
camera.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);

Categories

Resources