Beside needing to add WRITE_EXTERNAL_STORAGE
and READ_EXTERNAL_STORAGE
to your android/app/src/main/AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.yyy">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
...
</manifest>
You also need Runtime Request Permission, by using simple_permissions package:
import 'package:simple_permissions/simple_permissions.dart';
PermissionStatus permissionResult = await SimplePermissions.requestPermission(Permission. WriteExternalStorage);
if (permissionResult == PermissionStatus.authorized){
// code of read or write file in external storage (SD card)
}
Note:
- when running
SimplePermissions.requestPermission
for the First Time, app will popup a window, you MUST clickALLOW
:
to give permission.
- If you already clicked
DENY
, then uninstall debug app and re-debug it to install and fix this -> trigger the popup window and give you chance to clickALLOW
.