Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Result code always -1 #91

Open
Jmalinza opened this issue Sep 29, 2017 · 1 comment
Open

Result code always -1 #91

Jmalinza opened this issue Sep 29, 2017 · 1 comment

Comments

@Jmalinza
Copy link

Jmalinza commented Sep 29, 2017

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 Jmalinza changed the title Request code always -1 Result code always -1 Sep 29, 2017
@Jmalinza
Copy link
Author

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;
        }
    }
```

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant