Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple permissions not working #6

Closed
sunbyte opened this issue Sep 13, 2018 · 3 comments
Closed

Multiple permissions not working #6

sunbyte opened this issue Sep 13, 2018 · 3 comments

Comments

@sunbyte
Copy link

sunbyte commented Sep 13, 2018

Hi, this library don't work for me.
Can't ask for multiple permissions at the same time.
It asks only for the first one in the array.
I'm trying to allow both the READ and WRITE storage permissions at once, but without any success.

@nabinbhandari
Copy link
Owner

Hello, if you request and get the permission for WRITE_EXTERNAL_STORAGE, the permission READ_EXTERNAL_STORAGE will automatically be granted. If you have further issue, please include an example code which causes the problem.

@sunbyte
Copy link
Author

sunbyte commented Sep 13, 2018

I need WRITE_EXTERNAL_STORAGE permission to download a remote file and READ_EXTERNAL_STORAGE to give the user an option to open the downloaded file. When WRITE_EXTERNAL_STORAGE is allowed by the user, the download process start and the file is downloaded successful. But when I try to open the file, the app crashes.

Here is the code for opening file from storage (works perfect if the READ_EXTERNAL_STORAGE is allowed): https://pastebin.com/jZZvqjJw

@nabinbhandari
Copy link
Owner

I am unable to test your code because it lacks definitions of some methods. However. I did a simple write and read operation on a file and it is working fine.

Please test the following code in your device:

Manifest:

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

MainActivity:

String[] permissions = {Manifest.permission.WRITE_EXTERNAL_STORAGE,
        Manifest.permission.READ_EXTERNAL_STORAGE};
Permissions.check(this, permissions, null, null, new PermissionHandler() {
    @Override
    public void onGranted() {
        try {
            File root = Environment.getExternalStorageDirectory();
            File testFile = new File(root, "test.txt");

            FileOutputStream out = new FileOutputStream(testFile);
            out.write("Hello World".getBytes());
            out.close();

            FileInputStream in = new FileInputStream(testFile);
            byte[] data = new byte[11];
            in.read(data);
            in.close();

            String message = "Read: " + new String(data);
            Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
});

Note that you can simply just request WRITE_EXTERNAL_STORAGE only and it should work fine.

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

No branches or pull requests

2 participants