I take a picture with android :
bComenzarVisita.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
imageFileUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, new ContentValues());
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
startActivityForResult(i, CAMERA_PIC_INI_REQUEST);
}
});
The thing is when the user use front cam, the pic get flipped, and I want to rotate it in this case. Rotating and flipping is no problem.
How can I know in the method : onActivityResult which camera the user has used ( front or back)
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) {
case CAMERA_PIC_INI_REQUEST:
if (resultCode == RESULT_OK) {
// If front camera used, flip pic
}
break;
...
}
}
Related
I have built an Android application that allows the user to take pictures, I don't need to save the picture to the photo album but I want to give to picture a custom name and I don't know how to do.
This is how I open the camera:
addButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
});
and this is how I save the photo:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if( requestCode == CAMERA_PIC_REQUEST) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
DataManager.bars.get((Integer) getIntent().getSerializableExtra("bar")).images.add(thumbnail); // here I save the picture to my custom object
this.adapter.notifyDataSetChanged(); // I update the recycler view in order to see the pic
} else {
Toast.makeText(this, "Picture Not taken", Toast.LENGTH_LONG).show();
}
}
I'm capturing image from camera in horizontal scroll-view .When i select that image and display in full image in Image-view its getting very blurry. Why not display clear image in imageview.How to solve this .Thanks in advance
btnCamera.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
Log.e("Camera", " Open");
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST) {
Bitmap photoBitMap = (Bitmap) data.getExtras().get("data");}
}
Hi I am developing an app which requires to take pics which has to be sent over email. As the camera intent starts camera starts and it allows me to capture an image, when i press SAVE image is displayed in the image view.
Now i need to continue taking images, i.e., after pressing SAVE the camera should start again and be ready to capture pics till i click back button.
Could anyone please help?
For now my code is
Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(FileColumns.MEDIA_TYPE_IMAGE);
camIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(camIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
{
if (resultCode == RESULT_OK)
{
ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setImageURI(fileUri);
}
else if (resultCode == RESULT_CANCELED)
{
}
}
}
Trigger the same intent again on activity result to start the camera again and handle it here only till when you want to capture the images.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
{
if (resultCode == RESULT_OK)
{
ImageView img=(ImageView)findViewById(R.id.imageView1);
img.setImageURI(fileUri);
Intent camIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
fileUri = getOutputMediaFileUri(FileColumns.MEDIA_TYPE_IMAGE);
camIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(camIntent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
else if (resultCode == RESULT_CANCELED)
{
}
}
}
I read an text input from the user, this input i use it as a name of a picture i'm taking by the camera.
i store this name and the path of the image name into Sqlite Database.
what I'm trying to do is, after clicking OK to accept the taken picture, i want the saved path to be displayed in a toast.
the problem is, when I click OK to accept the picture, nothing is being displayed and i cant switch from the camera activity to the activity that called the camera activity"the previous activity"
Note: I'm using the emulator not a real device.
OnClickListener btn_TakePictureListener = new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String imgPath = retrievePath();
intent.putExtra(MediaStore.EXTRA_OUTPUT, getImageUri(imgPath));
startActivityForResult(intent, RequestCode);
}
};
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RequestCode && resultCode == RESULT_OK) {
String s = data.getData().toString();
Toast.makeText(getBaseContext(), ""+s, Toast.LENGTH_SHORT).show();
}
}
if you are passing Uri for you image then you can retrieve image as taken by camera:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(
Environment.getExternalStorageDirectory(), "temp.jpg")));
startActivityForResult(intent, 1);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
if (requestCode == 1) {
// Set the file save path with directory
File picture = new File(Environment.getExternalStorageDirectory()
+ "/temp.jpg");
Uri imageuri= Uri.fromFile(picture);
//set to imageview here
}
}
EDIT:
For Getting data uri in onActivityResult start Camra Activiyt as:
Intent intent = new Intent(Intent.ACTION_PICK, null);
intent.setDataAndType(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,IMAGE_UNSPECIFIED);
startActivityForResult(intent, 2);
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == NONE)
return;
if (requestCode == 1) {
Uri uriimg = data.getData();
Toast.makeText(getBaseContext(), ""+uriimg.toString(), Toast.LENGTH_SHORT).show();
}
}
I'd like to ask for your help concerning Android's built in Camera Interface
When i click capture, the screen captures(meaning it freezes)
But when i click ok, it hangs. It's suppose to go back to the main interface but it doesn't.
When i press cancel, it would force close.
the code is pretty long but this is my listener:
#Override
protected void onActivityResult(int requestCode, int
resultCode, Intent data)
{
super.onActivityResult(requestCode,
resultCode, data);
Double x = null;
Toast.makeText(mContext, x.toString(),Toast.LENGTH_LONG);
if (resultCode == Activity.RESULT_OK) {
switch (requestCode) {
case CAMERA_PIC_REQUEST:
image.setImageURI(uri);
break;
}
}
}
thanks..
This is the intent to call the camera interface.
Intent intentCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intentCamera, CALL_CAMERA);
`protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent){
if(requestCode == CALL_CAMERA && resultCode == RESULT_OK)
{
if(imageReturnedIntent.getAction() != null)
{
// display image received on the view
Bundle newBundle = imageReturnedIntent.getExtras();
newBitmap = (Bitmap) newBundle.get("data");
if(newBitmap != null)
{
ImageView imageViewProfilePicture = (ImageView) this.findViewById(R.id.imageViewProfilePicture);
imageViewProfilePicture.setImageBitmap(newBitmap);
imageViewProfilePicture.invalidate();
}
}
}}`
Solved!
The startActivityForResult() sub needs to be within the class. I placed mine inside my onclick which was inside my onCreate sub.
Thanks guys:D