-
Notifications
You must be signed in to change notification settings - Fork 72
Description
Trying to use share_handler to receive a file with a custom file extension into my Flutter app - managed to get it working in iOS, but not for Android.
The onDone event gets triggered ok, but media.attachements is always null. Any idea why I don't get the file itself?
This method is called from my Widget's initState():
late ShareHandlerPlatform _handler;
SharedMedia? media;
Future<void> initPlatformState() async {
_handler = ShareHandler.instance;
media = await _handler.getInitialSharedMedia();
print("**************> RECEIVED INITIAL MEDIA: ${media}");
// Listen to media sharing coming from outside the app while the app is in the memory.
_handler.sharedMediaStream.listen((SharedMedia media) {
if (!mounted) return;
print("**************> RECEIVED SHARED MEDIA: ${media}");
setState(() {
this.media = media;
print("**************> SETSTATE SHARED MEDIA: ${media.attachments}");
print("**************> media.content=${media.content}");
print("**************> media.imageFilePath=${media.imageFilePath}");
print("**************> media.serviceName=${media.serviceName}");
print("**************> media.senderIdentifier=${media.senderIdentifier}");
print("**************> media.conversationIdentifier=${media.conversationIdentifier}");
});
});
if (!mounted) return;
setState(() {
//_platformVersion = platformVersion;
});
}
In the console I see these messages when the file is tapped from my email:
I/flutter (29587): **************> RECEIVED SHARED MEDIA: Instance of 'SharedMedia' I/FileDirectory(29587): File name: emailRace.scrac I/flutter (29587): **************> SETSTATE SHARED MEDIA: null I/flutter (29587): **************> media.content=content://com.samsung.android.email.attachment.preview/f87658b3-c2aa-41d6-a3e7-ff66182a9a70 I/flutter (29587): **************> media.imageFilePath=null I/flutter (29587): **************> media.serviceName=null I/flutter (29587): **************> media.senderIdentifier=null I/flutter (29587): **************> media.conversationIdentifier=null
So, it is triggered ok, but no actual file.
Interestingly, something issued the message above:
I/FileDirectory(29587): File name: emailRace.scrac
So something knows about the file, but it never makes it back to my code.
Any ideas what I might have done wrong?
The second part of this is that I never get any media if my app is started fresh (not currently running) and I open the email attachment - it successfully opens my app, but there is nothing given in getInitialSharedMedia(). Similarly, any ideas what I've done wrong there too?
Thanks, John