Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/path_provider/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.2

* `getExternalStorageDirectory` now uses `getExternalFilesDir` on Android.

## 1.1.1

* Cast error codes as longs in iOS error strings to ensure compatibility
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package io.flutter.plugins.pathprovider;

import android.os.Environment;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
Expand Down Expand Up @@ -52,6 +51,6 @@ private String getPathProviderApplicationDocumentsDirectory() {
}

private String getPathProviderStorageDirectory() {
return Environment.getExternalStorageDirectory().getAbsolutePath();
return mRegistrar.context().getExternalFilesDir(null).getAbsolutePath();
}
}
9 changes: 6 additions & 3 deletions packages/path_provider/example/test_driver/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ void main() {
expect(result, throwsA(isInstanceOf<UnsupportedError>()));
} else if (Platform.isAndroid) {
final Directory result = await getExternalStorageDirectory();
// This directory is not accessible in Android emulators.
// However, it should at least have a fake path returned.
expect(result.path.length, isNonZero);
final String uuid = Uuid().v1();
final File file = File('${result.path}/$uuid.txt');
file.writeAsStringSync('Hello world!');
expect(file.readAsStringSync(), 'Hello world!');
expect(result.listSync(), isNotEmpty);
file.deleteSync();
}
});
}
2 changes: 1 addition & 1 deletion packages/path_provider/lib/path_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Future<Directory> getApplicationDocumentsDirectory() async {
/// On iOS, this function throws an [UnsupportedError] as it is not possible
/// to access outside the app's sandbox.
///
/// On Android this uses the `getExternalStorageDirectory` API.
/// On Android this uses the `getExternalFilesDir(null)`.
Future<Directory> getExternalStorageDirectory() async {
if (Platform.isIOS)
throw UnsupportedError("Functionality not available on iOS");
Expand Down
2 changes: 1 addition & 1 deletion packages/path_provider/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for getting commonly used locations on the Android &
iOS file systems, such as the temp and app data directories.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/path_provider
version: 1.1.1
version: 1.1.2

flutter:
plugin:
Expand Down