Describe the bug
This is on ANDROID only.
Hi. It seems that I can't do File.writeAsBytes() in the _backgroundMessageHandler. But works in _onMessageHandler.
Exception has occurred.
FileSystemException (FileSystemException: Cannot open file, path = 'Directory: '/data/user/0/com.mydomain.myapp/app_flutter'/150' (OS Error: No such file or directory, errno = 2))
import 'package:flutter/material.dart';
import 'dart:convert';
import 'dart:developer';
import 'dart:io';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:dio/dio.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as prefix0;
import 'package:provider/provider.dart';
// .....
Future<dynamic> _backgroundMessageHandler(Map<String, dynamic> message) async {
Future<String> downloadAndSaveImage(String url) async {
String decodedImgUrl = Uri.decodeFull(url);
List<String> arr = decodedImgUrl.split("?");
String filename = prefix0.basename(arr[0]);
filename = filename.replaceAll(":", ".");
var directory = await getApplicationDocumentsDirectory();
var filePath = '$directory/$filename';
try {
var response = await Dio()
.get(url, options: Options(responseType: ResponseType.bytes));
var file = File(filePath);
await file.writeAsBytes(response.data);
return filePath;
} on DioError catch (e) {
log("DioError: " + e.error.toString());
return "";
}
}
void getImagePath(String url) async {
String imagePath = await downloadAndSaveImage(url);
log(imagePath);
}
getImagePath("https://via.placeholder.com/150");
}
// .....

To Reproduce
Additional context
_backgroundMessageHandler on the top level Dart methodHi @rommyarb
could you please provide your flutter doctor -v
Thank you
Hi @rommyarb
could you please provide yourflutter doctor -v
Thank you
[β] Flutter (Channel stable, v1.9.1+hotfix.6, on Mac OS X 10.14.6 18G95, locale en-ID)
β’ Flutter version 1.9.1+hotfix.6 at /Users/rommy/development/flutter
β’ Framework revision 68587a0916 (8 weeks ago), 2019-09-13 19:46:58 -0700
β’ Engine revision b863200c37
β’ Dart version 2.5.0
[β] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
β’ Android SDK at /Users/rommy/Library/Android/sdk
β’ Android NDK location not configured (optional; useful for native profiling support)
β’ Platform android-29, build-tools 29.0.2
β’ ANDROID_HOME = /Users/rommy/Library/Android/sdk
β’ Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
β’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
β’ All Android licenses accepted.
[β] Xcode - develop for iOS and macOS (Xcode 10.3)
β’ Xcode at /Applications/Xcode.app/Contents/Developer
β’ Xcode 10.3, Build version 10G8
β’ CocoaPods version 1.7.5
[β] Android Studio (version 3.5)
β’ Android Studio at /Applications/Android Studio.app/Contents
β’ Flutter plugin version 40.2.2
β’ Dart plugin version 191.8593
β’ Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[β] VS Code (version 1.39.2)
β’ VS Code at /Applications/Visual Studio Code.app/Contents
β’ Flutter extension version 3.6.0
[!] Connected device
! No devices available
! Doctor found issues in 1 category.
Thank you for your response!
Thank you @rommyarb
issue possibly related to https://github.com/FirebaseExtended/flutterfire/issues/1325
issue possibly related to #1325
@iapicca this is #1325, typo? βΊοΈ
Hey all π
As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues.
If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.
Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.
Thanks everyone.