Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[share] Add sharing file support (android & ios) #970

Merged
merged 56 commits into from
Aug 28, 2020
Merged

[share] Add sharing file support (android & ios) #970

merged 56 commits into from
Aug 28, 2020

Conversation

pboos
Copy link
Contributor

@pboos pboos commented Dec 7, 2018

This pull request adds file sharing support to the share plugin.

Share.shareFile(File('${directory.path}/image.jpg'));

To use while it is not yet published in the share plugin, just use the following in your pubspec.yaml:

dependencies:
  ...
  share:
    git:
      url: https://github.com/pboos/plugins.git
      path: packages/share
      ref: feature/shareFile

@palancana
Copy link

Hi @pboos! What a nice work! Thank you very much for sharing, I find this completely necessary for the plugin!
One quick comment. To make things easier for people who don't know about this, I think we should mention in the README.md that adding some keys for iOS may be needed. For Android I think it's not needed, correct me if I'm wrong please. We could add something like this:

iOS
Add these keys to ios > Runner > Info.plist to be able to same images to the camera roll:

<key>NSPhotoLibraryUsageDescription</key>
<string>Access to save the image</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Access to save the image</string>

Android
There's no need to change anything.

@allanwolski
Copy link

Great job @pboos!

It would be perfect if had an option for multiple files like this
https://github.com/d-silveira/flutter-share

Could you add that?

@js2702
Copy link

js2702 commented Feb 6, 2019

I'm having issues sharing image files with WhatsApp on iOS. On Android it's working fine, is there any specific thing that needs to be done in order to share in WhatsApp?

@allanwolski
Copy link

When will this be merged?

@cyanglaz cyanglaz changed the title [share] Add sharing file support (android & ios) [share_preferences] Add sharing file support (android & ios) Feb 23, 2019
@cyanglaz cyanglaz changed the title [share_preferences] Add sharing file support (android & ios) [share] Add sharing file support (android & ios) Feb 23, 2019
@kitesoft
Copy link

When will this be merged?

@woellij
Copy link

woellij commented Feb 23, 2019

using the dependency as described by @pboos does not seem to work anymore with the migration away from android support library

E:\Dev\flutter\flutter\.pub-cache\git\plugins-32d70052e89ccb4ea8c528f174dd29023c037a16\packages\share\android\src\main\java\io\flutter\plugins\share\SharePlugin.java:10: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
E:\Dev\flutter\flutter\.pub-cache\git\plugins-32d70052e89ccb4ea8c528f174dd29023c037a16\packages\share\android\src\main\java\io\flutter\plugins\share\SharePlugin.java:11: error: package android.support.v4.content does not exist
import android.support.v4.content.FileProvider;
                                 ^
E:\Dev\flutter\flutter\.pub-cache\git\plugins-32d70052e89ccb4ea8c528f174dd29023c037a16\packages\share\android\src\main\java\io\flutter\plugins\share\SharePlugin.java:155: error: cannot find symbol
  @NonNull
   ^
  symbol:   class NonNull
  location: class SharePlugin
E:\Dev\flutter\flutter\.pub-cache\git\plugins-32d70052e89ccb4ea8c528f174dd29023c037a16\packages\share\android\src\main\java\io\flutter\plugins\share\SharePlugin.java:101: error: cannot find symbol
        FileProvider.getUriForFile(
        ^
  symbol:   variable FileProvider
  location: class SharePlugin
4 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':share:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://goo.gl/CP92wY for more information on the problem and how to fix it.
*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1

@yhunglee
Copy link

@pboos Hi, I'm an user of your great work. Thank you. I appreciate your great effort. It can be better if you make it to be merged. I wish it become true. Thank you.

@BGomes17
Copy link

Using this plugin in the way that @pboos described is giving a conflict with AndroidX.
Is there any forecast when this feature will be added to the share plugin?

@martinory
Copy link

I found it easy to refactor the plugin according to https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility as well as changing the NonNull and FileProvider to the latest imports in the SharePlugin.java-file:
import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
and in the androidmanifest.xml-file:
android:name="androidx.core.content.FileProvider"

@collinjackson
Copy link
Contributor

collinjackson commented Jul 25, 2019

At first glance looks like a solid change, and lots of thumbs on the PR. Conflicts need to be resolved.

Created flutter/flutter#36894 to track getting this merged, if this feature is something you need please thumbs up that issue.

@bulwinkel
Copy link

@collinjackson anything we can do to help this along?

@pboos
Copy link
Contributor Author

pboos commented Dec 18, 2019

What do I have to do to get this merged in? It seems like several people are interested in this and it would make it easier if it was merged into the official share plugin.

@joandervieira
Copy link

I also have problem conflict with AndroidX. My project not use AndroidX

`Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/filepaths) from [:open_file] AndroidManifest.xml:20:17-50
is also present at [:share] AndroidManifest.xml:15:17-65 value=(@xml/flutter_share_file_paths).
Suggestion: add 'tools:replace="android:resource"' to element at AndroidManifest.xml to override.

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute meta-data#android.support.FILE_PROVIDER_PATHS@resource value=(@xml/filepaths) from [:open_file] AndroidManifest.xml:20:17-50
is also present at [:share] AndroidManifest.xml:15:17-65 value=(@xml/flutter_share_file_paths).
Suggestion: add 'tools:replace="android:resource"' to element at AndroidManifest.xml to override.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 19s`

@JonasVautherin
Copy link

@pboos: I tried to fix the conflicts (your repo is 500+ commits behind upstream), but unfortunately I couldn't make the plugin work.

Would you mind fixing the conflicts (it seems to me that it shouldn't be too much work)? Also Flutter is complaining about AndroidX in my case, and it seems like this should be addressed as well.

Finally, the CI is all passing expect for the CLA saying: "CLAs are signed, but unable to verify author consent". Did you do everything on your side? I believe that the Flutter team won't be able to merge unless this test is passing.

It seems like the Flutter team doesn't have much resources to look into PRs, since this one has been waiting for more than a year. But at least if it was in a mergeable state, there would be a chance of it being merged some day 😊. Currently it is not.

@pboos
Copy link
Contributor Author

pboos commented Jan 3, 2020

I have updated my branch and rebased to a commit from two weeks ago (as of now the most recent). The many conflicts were due to the reason that the master share plugin was migrated to android plugin v2 and androidx. I now adjusted the code to that version.

Might require a new review of the code since especially the ios part changed a log (made it closer to the new version and as well fixed a bug that was there in the old version of my pull request).

Any further input to get this merged would be great.

@pboos
Copy link
Contributor Author

pboos commented Aug 26, 2020

@ditman did the corrections you suggest. I agree the shareFile did not really add any value. And seems like all tests passed now as well. I hope we can get somebody to review Android/iOS. Looks like we are getting closer to getting this merged 🤞 .

@cyanglaz
Copy link
Contributor

@pboos Thanks for the PR! It looks good overall. I left some comments around java and objc implementations.

@pboos
Copy link
Contributor Author

pboos commented Aug 28, 2020

@cyanglaz Thanks a lot for the great comments. I acted on them and now the code should be a lot better :). You caught some embarrassing bugs that snuck their way in there :)

@ditman ditman requested review from ditman and removed request for collinjackson August 28, 2020 17:37
Copy link
Member

@ditman ditman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, if @cyanglaz is happy, let's merge

@ditman ditman requested a review from cyanglaz August 28, 2020 17:48
Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! @ditman feel free to land it :)

@ditman
Copy link
Member

ditman commented Aug 28, 2020

All looks green, landing this now, will publish ASAP! Thanks for the contribution (and the patience) @pboos!!

@ditman ditman merged commit c62afee into flutter:master Aug 28, 2020
@ditman
Copy link
Member

ditman commented Aug 28, 2020

share: ^0.6.5 has been tagged and published!

@LasseRosenow
Copy link

Now as we have to put in the path of our files I wonder how I can share a base64 encoded File that I get from the network?

@pboos
Copy link
Contributor Author

pboos commented Aug 31, 2020

@ditman Thanks a lot for taking this on and getting it merged! 🚀

@lazylazyllama You could always temporarily store that file on the device within the app. The user won't even notice it. And as a note, before it was File, now it is the path. But even before it just forwarded the absolute path of the file in the background. So if something worked before, you can just do file.path now, as that is what it did before the recent changes on this PR.

KevinTheGray added a commit to KevinTheGray/plugins that referenced this pull request Aug 31, 2020
* master:
  [url_launcher, url_launcher_web]Added webOnlyWindowName parameter to launch()  (flutter#2979)
  [battery_platform_interface] Introduce package. (flutter#2975)
  [url_launcher_platform_interface] Add webOnlyWindowName parameter to launch() (flutter#2974)
  [share] Add sharing file support (android & ios) (flutter#970)
  [integration_test] add support to get timeline (flutter#2947)
  [battery] Moved battery to its own subdir (flutter#2969)
  [integration_test] Fix channel name for iOS, docs (flutter#2972)
  [integration_test] Show stack trace of widget test errors on the platform side (flutter#2967)
  [video_player] Fix `setWithOthers` test (flutter#2970)
  [video_player_platform_interface] fix `setMixIWithOthers` test channel (flutter#2968)
  Add README instructions for enablePendingPurchases (flutter#2921)
  Rebase previous commits (flutter#2966)
  Avoid walleye 26
  Updating documentation to use isEmpty check. (flutter#2955)
  [integration_test] Minor cleanup (flutter#2956)
  [path_provider, video_player] Tweak pubspecs to pass bulk analysis. (flutter#2959)
  [android_intent] fix platform package dep (flutter#2948)
  [shared_preferences_linux] update `file` package dep version to be compatible with framework (flutter#2950)
jorgefspereira pushed a commit to jorgefspereira/plugins_flutter that referenced this pull request Oct 10, 2020
Co-authored-by: Kifah Meeran <23234883+MaskyS@users.noreply.github.com>
Co-authored-by: Aloïs Deniel <alois.deniel@gmail.com>
Co-authored-by: Colin Stewart <colin@owlfish.com>
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
Co-authored-by: Kifah Meeran <23234883+MaskyS@users.noreply.github.com>
Co-authored-by: Aloïs Deniel <alois.deniel@gmail.com>
Co-authored-by: Colin Stewart <colin@owlfish.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.