F
F
falcro2022-02-19 18:30:18
Android
falcro, 2022-02-19 18:30:18

How to make file explorer on android?

Need to be able to load a .png image in a game made with Unity for later use. In this case, the target path is initially unknown, and the user must find the file on their own.
It is also known that root folders have different names for different devices.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexVWill, 2022-02-19
@AlexVWill

If it's simple, then something like this:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + "/sdcard/test.jpg"), "image/*");
startActivity(intent);

If the mind, then you need to check the permissions to access the gallery.
A piece of code would look something like this:
int permissionStatus = ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE);
                    if (permissionStatus == PackageManager.PERMISSION_GRANTED) {
                        Intent intent = new   Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                        startActivityForResult(intent, 2);
                    } else {
                        ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
                                REQUEST_CODE_PERMISSION_READ_EXTERNAL_STORAGE); // call onRequestPermissionsResult to select file from gallery
                    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question