Image from camera not set to ImageView - android

Image taken from a camera is not set even though the Code I'm using is from the android developer website. Please help. I don't get what I'm supposed to do. Sometimes, the OnActivityResult method isn't called either. Here is the code I am using:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
mImageView = (ImageView) findViewById(R.id.imageView);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dispatchTakePictureIntent();
}
});
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
ex.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
System.out.println("Created: " + mCurrentPhotoPath);
galleryAddPic();
return image;
}
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
private void setPic() {
// Get the dimensions of the View
// int targetW = mImageView.getWidth();
// int targetH = mImageView.getHeight();
//
// // Get the dimensions of the bitmap
// BitmapFactory.Options bmOptions = new BitmapFactory.Options();
// bmOptions.inJustDecodeBounds = true;
// BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
// int photoW = bmOptions.outWidth;
// int photoH = bmOptions.outHeight;
//
// // Determine how much to scale down the image
// int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
//
// // Decode the image file into a Bitmap sized to fill the View
// bmOptions.inJustDecodeBounds = false;
// bmOptions.inSampleSize = scaleFactor;
// bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);
mImageView.setImageBitmap(bitmap);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.d("", "onActivityResult: "+mCurrentPhotoPath);
if (requestCode == REQUEST_IMAGE_CAPTURE) {
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);
mImageView.setImageBitmap(bitmap);
}
}
}

If you start an activity for result, the request code identifies the request. So if you started camera activity with request code, REQUEST_TAKE_PHOTO then you must use the same request code in activity result i.e.
onActivityResult
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.d("", "onActivityResult: "+mCurrentPhotoPath);
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);
mImageView.setImageBitmap(bitmap);
}
}
UPDATE
Since you want to decodeFile, your mCurrentPhotoPath must be absolute file path and not uri.So remove "file:" from mCurrentPhotoPath
createImageFile
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
System.out.println("Created: " + mCurrentPhotoPath);
galleryAddPic();
return image;
}
Hope it helps you..

Related

Failure delivering result ResultInfo in Android development for Camera Activity

I am trying to capture an image and go to next intent with the image. This following code going to Camera Intent. But not going to second intent. Its returning java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity error. that means there is no data going to onResultActivity. If I put data!=null in the argument then its returning to 1st Activity. What I am missing? I have tested the mCurrentPhotoPath. Its returning the filePath.
String shopName;
double latitude, longitude;
private int REQUEST_IMAGE_CAPTURE = 0;
private Bitmap imageBitmap;
String mCurrentPhotoPath;
static final int REQUEST_TAKE_PHOTO = 0;
private File createImageFile() throws IOException {
// Create an image file name
#SuppressLint("SimpleDateFormat") String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = image.getAbsolutePath();
return image;
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button btnNext = (Button)findViewById(R.id.btnNext);
btnNext.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
if (photoFile != null) {
//Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_LONG).show();
Uri photoURI = FileProvider.getUriForFile(MainActivity.this,
"com.marketaccess.data.collector.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode != RESULT_CANCELED) {
Uri filePath = data.getData();
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream);
byte[] imageResource = stream.toByteArray();
Intent sendDataIntent = new Intent(MainActivity.this, SendData.class);
Bundle extras = new Bundle();
sendDataIntent.putExtras(extras);
sendDataIntent.putExtra("imageResource", imageResource);
startActivity(sendDataIntent);
}
}
I have tested the Manifest fileprover block. It seems like ok and returing path.

SetImageBitmap shows white blank full screen

I have a CardActivity that opens a CameraActivity. I have an imagebutton I press and then the native camera app opens and I can take a picture. I try to pass that back to my CardActivity using an intent with a ByteArray. But it gives me a blank white screen. It doesnt insert anything into the imageview. The Bitmap element is not null, it has something.
This is my switch for starting the camera activity and setting image:
switch (v.getId()) {
case R.id.pButton1:
Intent cam = new Intent(CardActivity.this, CameraActivity.class);
startActivity(cam);
returnImage2();
mImageView = (ImageView)findViewById(R.id.imageView);
mImageView.setImageBitmap(bitmap);
mImageView.setRotation(180);
break;
This is my returnImage2();
public void returnImage2() {
try {
bitmap = BitmapFactory.decodeStream(this.openFileInput("myImage"));
}
catch (Exception e) {
e.printStackTrace();
}
}
This is my cameraActivity:
public class CameraActivity extends Activity {
private String mCurrentPhotoPath;
private ImageView mImageView;
private Bitmap mImageBitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dispatchTakePictureIntent();
}
public void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
System.out.println("ERR CANNOT CREATE FILE");
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.android.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
private File createImageFile2() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
try {
mImageBitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(mCurrentPhotoPath));
cImageFromBitmap(mImageBitmap);
//mImageView = (ImageView)findViewById(R.id.imageView);
//mImageView.setImageBitmap(mImageBitmap);
//mImageView.setRotation(180);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public String cImageFromBitmap(Bitmap bitmap){
String fileName = "myImage";//no .png or .jpg needed
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
FileOutputStream fo = openFileOutput(fileName, Context.MODE_PRIVATE);
fo.write(bytes.toByteArray());
// remember close file output
fo.close();
} catch (Exception e) {
e.printStackTrace();
fileName = null;
}
return fileName;
}
}
I noticed you are using REQUEST_TAKE_PHOTO for starting your activity
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO)
but you are checking for REQUEST_IMAGE_CAPTURE on onActivityResult
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
ALSO:
I don't know why you are going through all this work to create a file. When you use ACTION_IMAGE_CAPTURE the bitmap itself comes back in the result intent:
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
try {
mImageBitmap = (Bitmap) data.getExtras().get("data");

Saving and displaying full size photo captured in android

I'm trying to take a photo with the camera and in the activity result method I want to save it and launch a new activity to display the photo from where I saved it, but the imageView stay empty, I used the code from android developer
and here is my code:
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException e) {
e.printStackTrace();
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.example.android.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
private File createImageFile () throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode,resultCode,data);
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
//Bundle extras = data.getExtras();
// Bitmap imageBitmap =(Bitmap) extras.get("data");
Intent formIntent= new Intent(MainActivity.this,FormActivity.class);
// formIntent.putExtra("img",imageBitmap);
formIntent.putExtra("path",mCurrentPhotoPath);
startActivity(formIntent);
}
}
the activity that shoud display the photo
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
String path = getIntent().getStringExtra("path");
mImageView = (ImageView) findViewById(R.id.imageView);
File imgFile = new File(path);
Toast.makeText(this, path, Toast.LENGTH_LONG).show();
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
mImageView.setImageBitmap(myBitmap);
}
}

Android Camera Example - Not Saving Image

I'm currently trying to implement the Camera within my app to take a full image and save it. I'm following the guide at android.com under the 'Save the Full-Size Photo' section.
The first part of that tutorial worked without a problem, but it seems to simply not save the full image for some reason. When using the setPic function, it will crash as the Bitmap it gets has a size of 0. The addGalleryPic function doesn't seem to add anything to the gallery either.
Thanks for your help!
Manifiest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Activity:
String mCurrentPhotoPath;
static final int REQUEST_TAKE_PHOTO = 1;
Creating the file.
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
Opening the Camera intent.
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
Overriding the Activity Result.
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Logger.d( "onResult: " + requestCode + " & " + resultCode );
if (requestCode == REQUEST_TAKE_PHOTO && resultCode == RESULT_OK) {
Logger.d( "Attempting to open: " + mCurrentPhotoPath );
galleryAddPic();
setPic();
}
}
Adding the image to the gallery.
private void galleryAddPic() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
And setting the image to the imageView.
private void setPic() {
// Get the dimensions of the View
int targetW = image.getWidth();
int targetH = image.getHeight();
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Both of these values are zero.
Logger.d( "Size: " + photoW + "x" + photoH );
// Determine how much to scale down the image
// **THIS LINE CRASHES - Divide by zero ( size is zero ).**
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);
image.setImageBitmap(bitmap);
}
I recommend that you get rid of String mCurrentPhotoPath and replace it with File mCurrentPhoto (or another name as you see fit). This will clear up a few bugs:
mCurrentPhotoPath = "file:" + image.getAbsolutePath(); results in a value that is neither a valid filesystem path nor a valid string representation of a Uri
File f = new File(mCurrentPhotoPath); results in an invalid File, because of the rogue file: you are putting on the filesystem path in the above bullet
BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions); will not work, because of the rogue file: you are putting on the filesystem path in the first bullet
Most of the time, you are using the File anyway. And then for decodeFile(), just call getAbsolutePath() at that point (BitmapFactory.decodeFile(mCurrentPhoto.getAbsolutePath(), bmOptions)).

Android - Take a picture not working

I'm trying to make a simple app:
I made a button, its onClick should call the camera intent, save the picture in the internal storage and then i want to put the picture in a custom listview gallery... for now I haven't made the listview because I'm having problems with the intent. the camera doesn't open and I don't know why even if the right permissions are in the manifest file
any help is appreciated, I've tried a lot of tutorials but I can't find the problem.
public class MainActivity extends Activity implements View.OnClickListener {
public static final String LOG_TAG = "LOG_TAG" ;
public static final int CAMERA_REQUEST = 1; /* ci serve la richiesta per la camera*/
private Button btCamera;
private Button btSavePicture;
private ImageView imageViewShowPicture;
private File imageFile;
/*attributi per salvare foto*/
private String savePicturePath;
/*_____________________________________________________________________________________________oncreate*/
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*Collego oggetti alla grafica*/
btCamera = (Button)this.findViewById(R.id.btCamera);
btSavePicture = (Button) this.findViewById(R.id.btSalvaFoto);
this.imageViewShowPicture = (ImageView) this.findViewById(R.id.ivMostraFoto);
/*listener*/
btCamera.setOnClickListener(this);
btSavePicture.setOnClickListener(this);
}
/*___________________________________________________________________________________________metodo TAKE A PHOTO*/
private void startTakeAPictureIntent(){
Intent takeAPictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, CAMERA_REQUEST);
}
}}
/*___________________________________________________________________________________________metodo crea image file*/
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
savePicturePath = "file:" + image.getAbsolutePath();
return image;
}
/*______________________________________________________________________________________metodo aggiungi alla gallery*/
private void addPicToGallery() {
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(savePicturePath);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
this.sendBroadcast(mediaScanIntent);
}
/*______________________________________________________________________________________metodo decodificare un'immagine scalata*/
private void setPic() {
// Get the dimensions of the View
int targetW = imageViewShowPicture.getWidth();
int targetH = imageViewShowPicture.getHeight();
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(savePicturePath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW/targetW, photoH/targetH);
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeFile(savePicturePath, bmOptions);
imageViewShowPicture.setImageBitmap(bitmap);
}
/*_____________________________________________________________________________________________onclick*/
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btCamera: {
Log.d(LOG_TAG, "Ho premuto btcamera");
Toast.makeText(MainActivity.this, "Camera clicked", Toast.LENGTH_SHORT).show();
startTakeAPictureIntent();
/*Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, RICHIESTA_FOTOCAMERA);*/
} break;
case R.id.btSalvaFoto:{
Log.d(LOG_TAG, "Ho premuto btsalvafoto");
Toast.makeText(MainActivity.this, "salvafoto clicked", Toast.LENGTH_SHORT).show();
}
}
}
/*_____________________________________________________________________________________________onActivity result*/
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) { /* se la richiesta mi da risultati*/
Bundle extras = data.getExtras();
Bitmap immagineBitmap = (Bitmap)extras.get("data"); /* prendi gli extra */
imageViewShowPicture.setImageBitmap(immagineBitmap); /*setto la imageview per mostrarla*/
}
}
}// chiude activity
Please try to add following permission and see.
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Please refer to https://developer.android.com/guide/topics/media/camera.html#manifest to see anything other you need to declare.

Categories

Resources