Android startActivityForResult (DEF-2878) (SOLVED)

I’m developing an extension, which will invoke system gallery to pick photo,I can use dmGraphics::GetNativeAndroidActivity() in C++ and in java, I can use this Context to start activity.
But how to receive the data picked from the system gallery?I don’t know how to implement the following function:

void onActivityResult(int requestCode, int resultCode, Intent data);

Anyone have ideas?

I don’t think this is possible currently. @Mathias_Westerdahl?

Is there any api in java?Such as dmGraphics::GetNativeAndroidActivity() in C++.

We have a task in the backlog to create a hook for onActivityResult (DEF-2878) but we don’t have an ETA for that I’m afraid.

2 Likes

I have an idea.I start an activity A, then startActivityForResult in A, so I can receive onActivityResult in A,but this require an custom AndroidManifest.xml that including the main game Activity: com.dynamo.android.DefoldActivity, I’m not sure how to rewrite this xml.

That sounds like it could work.

Unfortunately, getting the AndroidManifest.xml (or Info.plist for iOS) isn’t very convenient today.
You’ll have to unpack bob.jar
and get the file from the unpacked folder:

com/dynamo/bob/bundle/resources/android/AndroidManifest.xml com/dynamo/bob/bundle/resources/ios/Info.plist

After copying the manifest to your project, you can reference it from game.project and you’re good to go.

Ping @Erik_Angelin, where can you find bob.jar locally?

2 Likes

Well, there is no bob.jar in editor2, but you can find the files in the same directory in Defold.app/Contents/Resources/packages/defold-<sha1>.jar.

1 Like

OK.I’ll try it out.

Support for onActivityResult() has been added in Defold 1.2.134 (see release notes for details).

1 Like