Reputation: 452
i used many codes and all work on 4.0 but jelly bean Os did not support any code
try
{
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 1);
}
catch(ActivityNotFoundException anfe){
//display an error message
// String errorMessage = "Whoops - your device doesn't support capturing images!";
Toast toast= Toast.makeText(getApplicationContext(), "Whoops - your device doesn't support capturing images!", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
Upvotes: 0
Views: 492
Reputation: 1400
Add this code in your onCreate or on click of a button
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
private void startActivityForResult(Intent data, int requestCode) {
// TODO Auto-generated method stub
if (requestCode == CAMERA_REQUEST) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
yourActivity.pictureImg.setImageBitmap(photo);
}
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
//OI FILE Manager
filemanagerstring = selectedImageUri.getPath();
//MEDIA GALLERY
selectedImagePath = getPath(selectedImageUri);
photo = BitmapFactory.decodeFile(selectedImagePath);
yourActivity.pictureImg.setImageBitmap(photo);
}
}
Upvotes: 3
Reputation: 11
i think you have forgot to add permission in the manifest file i have no idea about Os but in android it is like it
<uses-permission android:name="android.permission.CAMERA"/>
Upvotes: 0