How to let a user choose a picture from the gallery to use in game ,LibGDX

android, libgdx

Solution

I've created an example libgdx project with android-specific code for invoking the library and retrieving the file path for the image selected by the user. Hope this will help you understand how the integration works. I have tested it on a couple of android devices. See https://github.com/miket-ap/libgdx-platform-specific-example

Problem

I'm a beginner learning LibGDX. I'm developing my first game in LibGDX where you can replace the enemy ball with selected picture (e.g. someones head) and then you dodge the enemy . In my mainmenu i have stage2d buttons and i want to have one button which lets a user choose the picture he wants to use in game. So i created a button and added a CLickListner to it. Now where do i go from here ? Is there a way to open the gallery in LibGDX and let the user choose a picture he wants to use ? Edit : So let's say I have an interface in my core project: ``` public interface OpenGallery { public void openGallery(); } ``` And in my android directory I create a Platform specific class that launches the intent ``` import android.content.Intent; import com.kubas.zaidimas.OpenGallery; public class GalleryOpener extends AndroidLauncher implements OpenGallery { private static final int SELECT_PICTURE = 1; @Override public void openGallery() { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"), SELECT_PICTURE); } ``` What should i do from this point ? So I can call it inside my mainmenu ?

Original source

Related problems