iPaulPro / aFileChooser

[DEPRECATED] Android library that provides a file explorer to let users select files on external storage.
Apache License 2.0
1.79k stars 850 forks source link

Result code always -1 #91

Open Jmalinza opened 6 years ago

Jmalinza commented 6 years ago

The activity is always returning a result code of -1. I've tried using logcat and Toast but it seems that the onCreate() function of FileChooserActivity doesn't even post the toast or logcat message.

I'm so confused because the GUI launches, so onCreate() must be executing. Included my code for starting the activity and dealing with the results.

screen shot 2017-09-29 at 4 25 20 pm
Jmalinza commented 6 years ago

Solved: make sure you have included

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

in you manifest file as well as a run-time permission checker which can ask the user for permission:

//check permissions
    public boolean checkPermissionExtertalStorage() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            int result = getApplicationContext().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
            return result == PackageManager.PERMISSION_GRANTED;
        }
        return false;
    }

    //permission dialog
    public void requestPermissionExtertalStorage() throws Exception {
        try {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    REQUEST_CODE);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }