I'd like to create an app that is the same as the default camera app only with one small modification (i.e. video disabled or extra functionality added). How do I do it?
Do I just get the source code of the camera app and modify it or is there a way to extend core components of the Android system?
bizso99,
You can call an Intent from your Activity that is simply the camera sans video functionality like so:
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, TAKE_PICTURE);
}
This will return a smaller thumbnail version of the image. If you want the full size you need to use the Mediastore.EXTRA_OUTPUT like so:
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
mImageFile = new File(pathToStoreImage); //file where image will be stored
mSelectedImagePath = mImageFile.getAbsolutePath(); //path to file where image will be stored
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
Then you can receive the picture in onActivityResult()
Android is open source, so you can download the source for every stock-app in android (not for the google apps like Maps). You can in fact download the most recent original camera app from the android git repo. The building of the apk is only possible if you download the whole android-source. For a overview how to build the android-source, see this howto. You could modify the source for your needs.
I'm quite sure that it is impossible to extend the camera-app without copying the source because there is no plugin-api (or similiar) for the camera-api.
Related
I am using Android 5.0 to implement an application which allows to automatically capture and save an image into my phone. Currently, I am using bellow code but it requires press the capture button in Capture UI of my phone. Is it possible to capture and save the image without press the capture button? For example, I just call the function myCaptureandSave(), then the phone will display Capture UI and intermediately capture the image and save, I do not need doing more step.
public void myCaptureandSave() {
String image_path = Environment.getExternalStorageDirectory() +"/"+System.currentTimeMillis()+".jpg";
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
//File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
File output = new File(image_path);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(output));
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
You have to use Camera Api. Create Service, running in background, which hold reference to this api and current SurfaceTexture, it is necessary, camera will be 'previewing to nowhere'. after that you'll be able to take pictures even if device is locaked
Yes it is possible, but I believe you can't do it using the internal camera (calling the intent). You have to use Camera2 API.
I made a library to use Camera2 API, you can take a look at it if you want:
https://github.com/omaflak/Android-Camera2-Library
In your case, simply pass a dummy SurfaceTexture for the preview and call takePicture().
Hope it will help
how to capture an image in background without using the camera application
i tried with this time ago and with little bit changes i got it.
Hope this helps..
I need to record Audio, And I would be pleased to use Built in Voice Recorder, but it would be nice to pass it parameters : Specific Path, Specific Quatlity, etc.
Is it posible?
I like this solution because code is very short:
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, AUDIO_RECORDING);
Here I have an example to copy file to specific location:
How can I specify the output file's folder when calling RECORD_SOUND_ACTION?
I guess it is not posible. If you need to customize it, you will need to develop your own activity. You can work with google Sample !
http://developer.android.com/guide/topics/media/audio-capture.html
I am currently trying to create an app which when taking a picture using the camera, when saving the image, it saves to a specific folder location and if the folder doesn't currently exist on the phone, it creates the folder and saves the file to that location. My code does not currently work, although I have tried. Could you please look at my code and advise me on what I need to do.
Here is the code:
else if(v==camera){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File newDirectory = new File(Environment.getExternalStorageDirectory() + "App_Pictures/");
String filename = new String("image1.jpeg");
File outputFile = new File(newDirectory, filename);
outputFile.mkdirs();
startActivity(intent);
}
It looks like you're trying to get an external app to take a picture for you. If this is the case, you need to use startActivityForResult, not startActivity, because you want to receive the resulting photo. Then you will receive the result in the onActivityResult method of your activity. This process is described in detail here.
If you actually want your own app to take the picture, instead of an external app, you'll need to use a completely different approach. Here is an app that starts recording a video right when it is launched, and saves it to a directory on the SD card, so perhaps it's a useful starting point if you want to do it this way.
i've been trying to create a camera-related app. i know that i could create it programmatically from top, but i would prefer using the one that the phone supports.
what i mean is, rather then creating the camera from 0, i would/could call the camera activity. after all, it provides all the system and gui that i needed.
however, the problem is i wanted the result/image took to be saved in a folder that i created before, rather then saving it in the default camera folder. and also renaming the image took that instant from the default 'image' to names that i preferred.
how do i control that ?
Try this. Here am saving picture to sdcard and also changing its name while saving.
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
Uri mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
"pic"+ String.valueOf(System.currentTimeMillis()) + ".jpg"));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
If you look at the Camera applicaton source code, it allows for startActivityForResult(..) that can return the image back to you. This is ideally what you'd like to do.
As a Little hint:
MediaStore
Use below method to take picture, SD_CARD_TEMP_DIR is the path and the image name you want it to store. Hope it help
private void takePicture(){
SD_CARD_TEMP_DIR = Environment.getExternalStorageDirectory() + File.separator + "farmerImage"+CassavaPref.getInstance(this).getImageSuffix()+".jpg";
file =new File(SD_CARD_TEMP_DIR);
Intent takePictureFromCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePictureFromCameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
startActivityForResult(takePictureFromCameraIntent, 1111);
}
I am working on an app in which i have to click a pic a pic and save it to a specified folder. I am using android.provider.MediaStore.ACTION_IMAGE_CAPTURE in intent to invoke the camera .I am done with coding and my activity is working fine.But now i have a question in my mind that whether i should stick with this code or i should use the code given here.Need your precious suggestions on this topic.
Thanx in advance.
If you want to just click a picture and save it to a specified folder nothing more then You can use Intent and call ACTION_IMAGE_CAPTURE, it easy to let handle on camera activity do your stuff,
And If your application has some serious deep work with camera when you want to modify preview screen size, and all those things,(For this you have to handle all things like to manage camera, and when to release it, check for don't freeze main UI..) then you have to go with the code you suggested...
Choice is yours.....
I suggest you use the code from your link.
Because most of the stock camera apps don't work as expected with Image Capture. For example the Galaxy S2 and most other Samsung and HTC phones give you the picture bytes back and also save the picture in the standard DCIM Folder on SD-Card, if you want it or not.
public void imageFromCamera() {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
Log.d(TAG, "No SDCARD");
} else {
mImageFile = new File(Environment.getExternalStorageDirectory()+File.separator+"MyApp",
"PIC"+System.currentTimeMillis()+".jpg");
mTempImagePath = mImageFile.getAbsolutePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mImageFile));
startActivityForResult(intent, TAKE_PICTURE);
}
}
this what u r searching i am thinking..