I am new to Android,I have a camera Code which works Fine in samsung s duos , but if i use micromax,karbon... etc it is not working,and in some Phones it will open front camera..etc
public static boolean checkCameraHardware(Context context) {
if (context.getPackageManager().hasSystemFeature(
PackageManager.FEATURE_CAMERA)) {
// this device has a camera
return true;
} else {
// no camera on this device
return false;
}
}
// camera code
public void openCamera() {
if (Helper.checkCameraHardware(this)) {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateFileName = sdf.format(new Date());
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
String curentDateandTime = sdf1.format(new Date());
File sdImageMainDirectory = new File(Environment
.getExternalStorageDirectory().getPath()
+ "/"
+ Helper.IMG_FOLDER + "/" + dateFileName);
if (!sdImageMainDirectory.exists()) {
sdImageMainDirectory.mkdirs();
}
String PATH = Environment.getExternalStorageDirectory()
.getPath()
+ "/"
+ Helper.IMG_FOLDER
+ "/"
+ dateFileName + "/";
// PATH = PATH OF DIRECTORY,image_PATH = full path of IMAGE
image_PATH = PATH + curentDateandTime + ".jpg";
System.out.println("image_PATH In open camera" + image_PATH);
File file = new File(PATH, curentDateandTime + ".jpg");
Uri outputFileUri = Uri.fromFile(file);
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
i.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(i, 1234);
} catch (Exception e) {
Helper.AlertBox(this,
"Error No: 001\nPlease contact Bluefrog technical person.\n"
+ e.toString());
}
} else {
Helper.AlertBox(this, "Image Not Captured.!");
image_PATH = "";
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
// image_PATH = "";
image_str = "";
// super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1234) {
if (resultCode == RESULT_OK) {
// restorePreferences();
Log.e("image_PATH in OnActivityResultSet", "File exist at "
+ image_PATH);
File file = new File(image_PATH);
if (file.exists()) {
Log.e("File exist condition :", "File exist at "
+ image_PATH);
try {
iv_MEPhoto.setImageBitmap(Helper.getImage(file
.getPath()));
iv_MEPhoto.setVisibility(View.VISIBLE);
photoTaken = true;
SENDING_IMAGE_PATH = image_PATH;
Log.e("File exist condition :", "File exist at "
+ image_PATH);
} catch (Exception e) {
Helper.AlertBox(this,
"Error No: 004\nPlease contact Bluefrog technical person.\n"
+ e.toString());
Log.e("Error reading file", e.toString());
}
} else {
Helper.AlertBox(this,
"Error No: 005\nPlease contact Bluefrog technical person.");
}
} else {
image_PATH = "";
Helper.AlertBox(this, "Image Not Captured.");
}
}
}