I need my flutter app to receive media(image/pdf etc) from external applications. I tried using receive_sharing_intent.
From my manifest:
<!--For receiving media from external applications-->
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
</activity>
and:
late StreamSubscription _intentSub;
final _sharedFiles = <SharedMediaFile>[];
@override
void initState() {
super.initState();
// Listen to media sharing coming from outside the app while the app is in the memory.
_intentSub = ReceiveSharingIntent.instance.getMediaStream().listen((value) {
setState(() {
_sharedFiles.clear();
_sharedFiles.addAll(value);
print(_sharedFiles.map((f) => f.toMap()));
});
}, onError: (err) {
print("getIntentDataStream error: $err");
});
// Get the media sharing coming from outside the app while the app is closed.
ReceiveSharingIntent.instance.getInitialMedia().then((value) {
setState(() {
_sharedFiles.clear();
_sharedFiles.addAll(value);
print(_sharedFiles.map((f) => f.toMap()));
// Tell the library that we are done processing the intent.
ReceiveSharingIntent.instance.reset();
});
});
}
@override
void dispose() {
_intentSub.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const PreferredSize(
preferredSize: Size.fromHeight(60),
child: HomeAppBar(),
),
body: Column(
children: [
..._sharedFiles.map((f) {
return ListTile(
title: Text(" path ${f.path}"),
subtitle: Text(f.type.value),
);
}).toList(),
],
),
);
}
But I am not getting anything inside the body. I need android only and I am pretty sure I handled all the configuration correctly.
Flutter version: 3.22.0