Comments (3)
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.
from android-permissions.
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
from android-permissions.
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.
from android-permissions.
Related Issues (20)
- min SDK 16 problem HOT 1
- Crash on Android 9.0 when using this library outside of an Activity HOT 5
- App Crashes on Android 6.0 Only (android.util.AndroidRuntimeException:) HOT 2
- Any way to center the text of the dialog? HOT 1
- Is it possible to call and get permission callbacks in Fragment? HOT 1
- Runtime Exception HOT 2
- PermissionHandler callbacks are never called for separate process
- Crash on Android Q HOT 1
- One time i check "Set Not to ask again", it always show setting dialog HOT 1
- Change color HOT 1
- Options when checking for single permission HOT 1
- Not showing rational message HOT 1
- targetSdkVersion HOT 1
- Migrate from JCenter HOT 18
- Not working for android 13 HOT 1
- issue with android 13 HOT 1
- Where are the new versions published? HOT 1
- I never see the permission request. HOT 1
- Unable to see the custom rationale dialog on app start or at least it's random HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-permissions.