i just want to know is there any way to launch the front camera using just intent. i don't want to use intent.putextra thing. so basically my code should look like this
btnFrontCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent camera = new Intent("android.media.action.IMAGE_CAPTURE");
startActivity(camera);
}
});
But above code is launching the back camera. i want to launch the front camera directly.
Help me with this if it is possible in Android.
i just want to know is there any way to launch the front camera using just intent
No.
i don't want to use intent.putextra thing.
That is fine, as there is no "intent.putextra thing" that controls which hardware camera the user's chosen camera app will use. The choice of camera is between the camera app and the user, through the camera app's UI. You do not get a vote.
If you want to take a picture and force that to be taken using a front-facing camera (if one is available), you will need to take the picture yourself using the camera APIs, not by invoking a third-party camera app.
Related
I just need to put a camera inside one of the three fragments of my main activity, like ([f]-[f]-[C]), where () is my main activity, [] is a fragment, C is the camera and f are just a fragment (they are full screen swipable). I need to create a whole camera (coding , etc) just for it or it is possible to call android native camera app with intent to an fagment?
I need to create a whole camera (coding , etc) just for it
Yes, whether you write it yourself or use one from a library.
or it is possible to call android native camera app with intent to an fagment?
No, you cannot embed a third-party app in a fragment of your app.
If you need to take a picture, you can just use an intent to launch the system camera app. Doing so will make it a lot easier to code, but you won't be able to show a live preview, as you're actually handling control to the camera app through that intent.
Manually handling the entire camera lifecycle allows you to have control over the preview and show it real-time in your app. Also, if you need to have the live preview in your app, this is the way to go and can't be accomplished using just an Intent.
You might find the UltimateAndroidCameraGuide on GitHub very helpful for your problem, particularly the SimpleCameraIntentFragment and the NativeCameraFragment files in that repo.
You can use an Intent to launch the camara and it will launch the camara default app., just be careful to detect when your "C" fragment is displayed, here: How to determine when Fragment becomes visible in ViewPager
If you dont do that, android pre-caches fragment before showing it and your intent will fire.
On your activity use:
#Override public void onResume() {
super.onResume();
if(viewPager.getCurrentItem() == 2){
//Your code here. Executed when fragment is seen by user.
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
}
See for camera launch with intent options: http://developer.android.com/guide/topics/media/camera.html#intent-image
I was trying to implement the quick camera myself and was unable to either unlock the screen or launch the camera in secure mode. Please help me with this.
I finally solved the problem using a separate intent for secure camera and lunching it when the screen is locked i.e keyguard.
if(kgMgr.inKeyguardRestrictedInputMode()){
Intent secure_camera_intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA_SECURE);
secure_camera_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
this.startActivity(secure_camera_intent);
}
i am creating an application.
and use device default camera to take picture.
using this
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, CAMERA_PICTURE);
in onActivityResult() method i call again above code and take picture again.
but i want to take multiple pictures at a time. is there any way to take picture automatically when camera is called by intent (not by creating custom camera activity).
By sending intent you just say to existing camera application that it start and allow user to take picture - you are completely on the mercy of this application. Some of them may contain some undocumented parameters allowing you to snap picture automcatically.
http://developer.android.com/guide/topics/media/camera.html#intent-image
If you like to have control, you shall code camera application yourself.
I suppose you have to write your own custom camera, as there is no extra in MediaStore class that would allow taking another picutre.
I am working on an app that accesses the camera and returns an uri, which I pass to another activity and display the extracted bitmap in an ImageView. Everything seems to work fine. Here is the code that I use to initiate the camera intent.
mCameraButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCameraUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraUri);
mtimeCameraAcessed = System.currentTimeMillis();
startActivityForResult(cameraIntent, RECEIVE_CAMERA_PICTURE);
overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
}
});
But, I have noticed a discrepancy. When my application access the camera, the gallery icon at the bottom of the screen seems to be missing (the icon appears when you access the camera application on any android phone). I have attached a couple of screenshots to illustrate this.
I want the user to access the camera while being able to change his/her mind and then access the gallery on the same screen (by tapping the gallery icon). Now, I do know how to initiate a gallery intent via 'Intent.ACTION_PICK'. I have also looked at the this question, but I don't completely agree that I need a custom camera layout to achieve what I intend to do: Single intent to let user take picture OR pick image from gallery in Android
The reason I say this is because, I have seen apps such as QuickPic that access the camera application with the gallery icon at the bottom. Can anyone please throw some light on this?
After going through some thorough research, I have come to a conclusion that this is infact impossible. However, a custom layout combined with the camera api would be the ideal solution if something like this is desired. But then, I have observed that using the camera api has certain problems such as skewed appearance of the camera screen.
QuickPic takes the user to the camera screen (with the gallery icon) but drops him/her out of the app while doing so. At that point, the user is basically using the stock camera app on Android and not the Quickpic app itself.
I am new to android programming.
I built an app which launches the camera via an intent when a button is pressed. But my requirement is that as soon as the camera is launched, it should capture the image autmatically after appropriately focusing it without clicking the camera shutter button and store the image in SD card.
it would a great help if i could get a source code.
thanks
my code is :-
unsuccess_button.setOnClickListener(new Button.OnClickListener()
{
public void onClick(View view)
{ add_text.setText("Not Successful");
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivity(cameraIntent);
}
});
You can use the surface view to get the Image from the camera and Camera hardware API to control the camera. May this will help you
In Addition to this you can change your code to take the picture in some timer event/launch of your activity.
You can use TimerTask or Thread to perform capturing event at some particular time period. I had developed same application.