KasemJaffer / receive_sharing_intent

A Flutter plugin that enables flutter apps to receive sharing photos, text and url from other apps.
Apache License 2.0
334 stars 395 forks source link

How to allow to share only specific files types ? #325

Open tempo-riz opened 1 month ago

tempo-riz commented 1 month ago

I want to recieve only audio files (public.audio) How can i show my app in the dialog only for audio files please ?

CodingCrog commented 1 month ago

You can differentiate between mimetypes, I did it to not break my other deeplinks like:

`void subscribeIntentDataStream() { if (_intentSub != null) { return; } _intentSub = ReceiveSharingIntent.instance.getMediaStream().listen((value) { bool isSharedMedia = value.any((item) => item.mimeType.toString().startsWith('image') || item.mimeType.toString().startsWith('video') || item.mimeType.toString().startsWith('document') || item.mimeType.toString().startsWith('text'));

  if (value.isNotEmpty && isSharedMedia) {
      Messenger.initShareMedia(value);
    _navigateToSharedMediaPage();
  }
}, onError: (err) {
  Logger.logError("getIntentDataStream error: $err");
});

}

In your case you can look if its an audio: item.mimeType.toString().startsWith('audio')

tempo-riz commented 1 month ago

Thanks @CodingCrog but I was looking for a step before, if possible to allow only to share audio, with your solution users will be able to share any filetype, but if it's not audio it will just open the app and do nothing. I don't know if that's possible tho...