Hello guys,
A few days ago, I want to call Android native camera in my project, but can't find any tutorial, so I decided to try to solve this problem.
Step 1. Create a Activity which can access the front camera and take picture.
Step 2. Create a Singleton(extends Godot.SingletonBase), which have a method "open", and it can start the new Activity.
Here are the screenshots


But the new questions appeared:
Q1: When the camera take a picture, and saved it, how can I accesse in GDScript ?
Q2: When the camera take a picture, and finished the activity, how to notify GDScript, may be a calback function ?
Java Code
public void open() {
Intent intent = new Intent();
intent.setClass(activity, CameraCallActivity.class);
activity.startActivityForResult(intent, CAMERA_REQUEST_CODE);
}
protected void onMainActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
toast("Take Picture Success");
// TODO need to notify
}
else {
toast("Take Picture Cancel");
}
}
}
GDScript Code
func _on_open_camera_pressed():
if not Globals.has_singleton("CameraSingleton"):
return
var single = Globals.get_singleton("CameraSingleton")
single.open()
#need to get the picture as a head image