I'm developing an app where when you log in, you should take a picture!
I researched and found the following example :
public class PhotoHandler implements Camera.PictureCallback {
private final Context context;
public PhotoHandler(Context context) {
this.context = context;
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFileDir = getDir();
if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {
Log.d("DEBUG_TAG", "Can't create directory to save image.");
Toast.makeText(context, "Can't create directory to save image.",
Toast.LENGTH_LONG).show();
return;
}
String photoFile = "Picture_.jpg";
String filename = pictureFileDir.getPath() + File.separator + photoFile;
File pictureFile = new File(filename);
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (Exception error) {
Toast.makeText(context, "Image could not be saved.",
Toast.LENGTH_LONG).show();
}
}
}
It uses the android.hardware.Camera
that is deprecated!
How can I perform this same action using android.graphics.Camera
?
This action must be transparent to the User.
By clicking the login button, he should choose the time and automatically take the photo!