1
I’m developing an app where when you login, you should take a photo!
I looked into it 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();
}
}
}
He uses the android.hardware.Camera
deprecated!
How can I perform this same action using the android.graphics.Camera
?
This action must be transparent to the User.
By clicking the login button, he must choose the time and automatically take the photo!
android.graphics.Camera or will be android.hardware.Camera2? If it is
android.hardware.Camera2
remember that the app will only run in Android 5 or more.– ramaral
So, it’s for version 4.4 ! I didn’t get to test the Camera2! As soon as possible I test and update! Thank you @ramaral
– Thiago Luiz Domacoski
If it’s for 4.4, you’ll have to use it android.hardware.Camera. The fact that it is considered obsolete only means that it should not be used when it is possible to use the one that replaces it.
– ramaral
So @ramaral, the problem is that it doesn’t work! I implemented, and when I call the takePicture does not perform! Debugging, he calls, but does not call the onPictureTaken I’ll do some more tests! Thank you!
– Thiago Luiz Domacoski
@ramaral don’t forget to leave a reply.
– Jorge B.