EddyVerbruggen / SocialSharing-PhoneGap-Plugin

šŸ‘Øā€ā¤ļøā€šŸ’‹ā€šŸ‘Ø Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget
MIT License
1.78k stars 906 forks source link

Failed to find configured root that contains #754

Closed samarthagarwal closed 7 years ago

samarthagarwal commented 7 years ago

I am getting the following error when trying to share a file from a remote URL.

Error Screenshot

Here is my code.

var options = {
          message: 'share this', // not supported on some apps (Facebook, Instagram)
          subject: 'the subject', // fi. for email
          files: ["http://ngcordova.com/img/ngcordova-logo.png"], // an array of filenames either locally or remotely
          url: 'http://ngcordova.com/',
          chooserTitle: 'Pick an app' // Android only, you can override the default share sheet title
        }

        var onSuccess = function (result) {
          alert("Share completed? " + result.completed); // On Android apps mostly return false even while it's true
          alert("Shared to app: " + result.app); // On Android result.app is currently empty. On iOS it's empty when sharing is cancelled (result.completed=false)
        }

        var onError = function (msg) {
          alert("Sharing failed with message: " + msg);
        }

        window.plugins.socialsharing.shareWithOptions(options, onSuccess, onError);
rebrandsoftware commented 7 years ago

I'm having the same failure and error message when I try to send a base64 encoded file, with this code:

    var options = {
      message: tweetText, // not supported on some apps (Facebook, Instagram)
      //subject: 'the subject', // fi. for email
      files: [picture], // an array of filenames either locally or remotely
      chooserTitle: 'Pick an app' // Android only, you can override the default share sheet title
    };

    var onSuccess = function(result) {
      console.log("Share completed? " + result.completed); // On Android apps mostly return false even while it's true
      console.log("Shared to app: " + result.app); // On Android result.app is currently empty. On iOS it's empty when sharing is cancelled (result.completed=false)
    };

    var onError = function(msg) {
      console.log("Sharing failed with message: " + msg);
    };

    window.plugins.socialsharing.shareWithOptions(options, onSuccess, onError);
EddyVerbruggen commented 7 years ago

What does Google tell us about this error?

samarthagarwal commented 7 years ago

I am pretty sure it is something related to file permissions. I checked the permissions in the manifest file and it is okay. I could not find a solution that is why I posted here.

angeagu commented 7 years ago

Same here with this code for trying to share file in /storage/emulated/0/

Code:

`var options = { message: 'share this', // not supported on some apps (Facebook, Instagram) //subject: 'the subject', // fi. for email files: ['file:///storage/emulated/0/CalendarExport.json'], // an array of filenames either locally or remotely chooserTitle: 'Pick an app' // Android only, you can override the default share sheet title }

            var onSuccess = function (result) {
                alert("Share completed? " + result.completed); // On Android apps mostly return false even while it's true
                alert("Shared to app: " + result.app); // On Android result.app is currently empty. On iOS it's empty when sharing is cancelled (result.completed=false)
            }

            var onError = function (msg) {
                alert("Sharing failed with message: " + msg);
            }

            window.plugins.socialsharing.shareWithOptions(options, onSuccess, onError);`
angeagu commented 7 years ago

Think I got a clue:

I saw in /res/xml/sharing_paths.xml the following element:

<external-files-path name="socialsharing_downloads" path="socialsharing-downloads/" />

Checking my android.support.v4.content.FileProvider, there's no tag for that element, just:

private static final java.lang.String META_DATA_FILE_PROVIDER_PATHS = "android.support.FILE_PROVIDER_PATHS";
  private static final java.lang.String TAG_ROOT_PATH = "root-path";
  private static final java.lang.String TAG_FILES_PATH = "files-path";
  private static final java.lang.String TAG_CACHE_PATH = "cache-path";
  private static final java.lang.String TAG_EXTERNAL = "external-path";
  private static final java.lang.String ATTR_NAME = "name";
  private static final java.lang.String ATTR_PATH = "path";

So this class is using "external-path" as tag, not "external-files-path". I commented that element in sharing_paths.xml and added following: <external-path name="external_path" path="." />

Then, I ran application again and tried to share a PDF file with Gmail application, and the file appears now as attached. Now the problem is that when I send the message, file is not really sent; just the message without the file.

Hope this give some light on the issue and let's check if we can manage to make it work....

rebrandsoftware commented 7 years ago

Just FYI my code sending base64 (which shouldn't even need to access a file location, right? Or perhaps there is a temp file being created?) works fine if I revert back to 5.1.1 of cordova-plugin-x-socialsharing on NPM.

samarthagarwal commented 7 years ago

I can confirm @rebrandsoftware that 5.1.1 works.

angeagu commented 7 years ago

Have removed plugin and reinstalled version 5.1.1 too and works. Thanks for the info @rebrandsoftware

EddyVerbruggen commented 7 years ago

@rebrandsoftware Any particular reason to use 5.1.1 over 5.1.2 or 5.1.3? Did you test those and confirmed they have the same issue?

I'm asking because my main suspect is the PR I accepted recently which was part of 5.1.4..

macdonst commented 7 years ago

@EddyVerbruggen everything works fine up to 5.1.3 and the bug appears once I upgrade to 5.1.4.

EddyVerbruggen commented 7 years ago

@macdonst thanks for confirming that - #748 is doing more harm than good it seems.

EddyVerbruggen commented 7 years ago

Although I can think of more fun things, I will be solving this this weekend.

EddyVerbruggen commented 7 years ago

I can reproduce the crash that was introduced with 5.1.4, but can't reproduce the problem that it tried to solve.

However, I've now pushed a change to this repo's master branch that's supposed to fix the problem for all cases.

Would be great if someone that had the problem with 5.1.3 and before on Android SDK 24+ could verify it works correctly.

rebrandsoftware commented 7 years ago

Hey, no reason I chose 5.1.1 other than I saw someone else having luck with 5.1.1. I will see what happens with other versions in just a moment.

EddyVerbruggen commented 7 years ago

@rebrandsoftware no need as @macdonst already confirmed it, but if you want: please verify the latest from github works fine (not released to npm yet)

rebrandsoftware commented 7 years ago

I can verify that the error I was having has been fixed in the latest from Github. However, I was testing on Android SDK 23. Sounds like you will still need confirmation from others with SDK 24+.

EddyVerbruggen commented 7 years ago

Correct. But a regression test never hurts, cheers!

nicobytes commented 7 years ago

The same error =( When I use shareViaWhatsApp screenshot from 2017-01-24 16-13-47

nicobytes commented 7 years ago

Just commenting that if anyone has a workaround, a temp hack, I'd definitely appreciate it.

nicobytes commented 7 years ago

Ok ok I'm sorry I tried with cordova plugin add cordova-plugin-x-socialsharing and not work, but I tried cordova plugin add https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin.git and now the plugin work!!!

EddyVerbruggen commented 7 years ago

@nicobytes so you've essentially tested the fix I asked folks to test, that's awesome šŸ˜„ I'll release an update to npm today.

EddyVerbruggen commented 7 years ago

Released with 5.1.6.

michaelpeterlee commented 7 years ago

I confirm now working again for Android, was not sharing files due to prior regression.

sdaly31 commented 2 years ago

I am having this same issue on 6.0.3. Is anyone else?