+2 votes

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
MainActivity
CameraCallActivity

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
in Engine by (86 points)

Did you get any further result?

Help needed. Were you successful in trying to store and access the pictures from the camera?

I have the same problem :c

1 Answer

+1 vote

I'm no java developer expert, but I think you should integrate your code with something like:

https://developer.android.com/training/camera/photobasics.html

-j

by (1,469 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.