5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Flutter、いくつかある写真保存先の整理

Last updated at Posted at 2020-02-16

動機

camera pluginやいくつかのサイトで、写真の保存先を指定するのにpath_providerを使用しているのを見かけるけれど、path_providerが提供するパスが当初わからず、からの、DCIMやPicturesに保存するときはどうすればいいのかと思っていじってみたものの整理。

得られるパス(例) 保存先の確認方法 アプリ削除時 android,ios
getApplicationDocumentsDirectory /data/user/0/com.example.package_name/app_flutter run-as package_nameで見に行ける。 消える 両対応
getExternalStorageDirectory /storage/emulated/0/Android/data/com.example.package_name/files adb shell cdで見に行ける。 消える androidのみ

保存先の確認方法メモ

getApplicationDocumentsDirectoryでの方法
adb shell
run-as package_name
getExternalStorageDirectoryでの方法
adb shell
cd 保存先パス

path_providerで得られる領域はアプリ専有部の領域で、設定などに寄るのだろうけれど、エクスプローラー的なのだと見えないぽい。

DCIMやPicturesへの保存方法

permission_handlerと保存先を直接指定をして出来た。

//事前に初期化などはしておく。
//controller = CameraController(cameras[0], ResolutionPreset.low);

// 保存先を直接指定
final String dirPath = '/storage/emulated/0/DCIM';
//final String dirPath = '/storage/emulated/0/Pictures';

//permission_handlerでDCIM、Picturesなどの共有部のパーミッションを得る(確認をとる)
Map<PermissionGroup, PermissionStatus> permissions = await PermissionHandler().requestPermissions([PermissionGroup.storage]);

String timestamp() => DateTime.now().millisecondsSinceEpoch.toString();
final String filePath = '$dirPath/${timestamp()}.jpg';

await controller.takePicture(filePath);

参考:http://blog.lciel.jp/blog/2014/02/08/android-about-storage/

その他

パッケージのリスト取得方法

adb shell pm list packages

permission_handlerをinstallしたらビルドし直す。

hot reloadだけだったのでpermission_handlerが動かなくてハマった。

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?