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

Android Twitter Share Launches Direct Message Not Compose Window #1153

Open Akz47 opened 2 years ago

Akz47 commented 2 years ago

Dear All,

It appears that Twitter Android now has 2 intents, to launch Direct Message or Compose Window.

When sharing on Twitter (i.e. shareViaTwitter() or share()), the plugin now launches the Direct Message window, but should be using the Compose Window instead. How do we specify the correct action / intent for Twitter, or default it to Compose Window?

We are using plugin version 6.0.3, latest Twitter Android app, and the issue exists on Android 6 - 11 devices.

Thank you.

JamesB1976 commented 2 years ago

We've been having this issue too. To go directly to the Compose window, we've found that this seems to work:

appPackageName: 'com.twitter.android/com.twitter.composer.ComposerActivity'

(If using shareWithOptions)

Or alternatively:

window.plugins.socialsharing.shareVia('com.twitter.android/com.twitter.composer.ComposerActivity', 'Message via Twitter', null, null, null, onSuccess, onError);

A couple of negatives though:

1, We've only tested this on Android 11 and with the latest Twitter app. We don't know if the same code will work on older versions of Android or older versions of the Twitter app.

2, This seems to send through undefined for result.completed and result.app, regardless of whether anything was shared or not. So we haven't found a way to properly check for a shared post.

But hopefully the above info might help someone. If you get any further with it, please let me know!

Akz47 commented 2 years ago

Thank you @JamesB1976, this is very helpful indeed. We will try this out and see if it works on some of our older devices.

Most likely we'll test this custom package name for Android 11 users first to be safe. I think it's an issue with Twitter now having 2 main intents, so Android 11 auto defaults to the first one (which is the private message one).

Have you had any such issues for iOS devices?

We've been having this issue too. To go directly to the Compose window, we've found that this seems to work:

appPackageName: 'com.twitter.android/com.twitter.composer.ComposerActivity'

(If using shareWithOptions)

Or alternatively:

window.plugins.socialsharing.shareVia('com.twitter.android/com.twitter.composer.ComposerActivity', 'Message via Twitter', null, null, null, onSuccess, onError);

A couple of negatives though:

1, We've only tested this on Android 11 and with the latest Twitter app. We don't know if the same code will work on older versions of Android or older versions of the Twitter app.

2, This seems to send through undefined for result.completed and result.app, regardless of whether anything was shared or not. So we haven't found a way to properly check for a shared post.

But hopefully the above info might help someone. If you get any further with it, please let me know!

undergroundcreative commented 2 years ago

Glad to hear it was useful! Please let me know how your testing goes and whether you encounter any issues. We'll probably be implementing it ourselves in the next few weeks.

We haven't had any similar problems with iOS, just seems to be an Android thing.

sdaly31 commented 2 years ago

@Akz47, Any results for your testing for various android versions? I would like to implement @JamesB1976 solution but would need support to be confirmed for various android versions. Thanks!

Akz47 commented 2 years ago

@JamesB1976 and @undergroundcreative, yes the ComposerActivity launches the proper Tweet composer correctly instead of the Direct Message.

We didn't have enough variety of Android versions / devices to test, so we implemented the following logic to check if the ComposerActivity activity is valid, else fallback to shareViaTwitter.

window.plugins.socialsharing.canShareVia('com.twitter.android/com.twitter.composer.ComposerActivity', msg, null, null, null, 
    function() {
        window.plugins.socialsharing.shareVia('com.twitter.android/com.twitter.composer.ComposerActivity', msg, null, null, null, successCallback, errorCallback);
    },
    function() {
        window.plugins.socialsharing.shareViaTwitter(msg, null, null, successCallback, errorCallback);
    }
);

We don't know for sure if that canShareVia check is accurate, but so far it seems to work fine even on an Android 5 test device.

sdaly31 commented 2 years ago

Thanks! Has anyone had any luck passing a base 64 encoded image this way? I can't seem to make that work. I opened an issue here.

https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/issues/1169

JamesB1976 commented 2 years ago

@Akz47 Good thinking about the 'canShareVia' logic, we've implemented a slightly tweaked version of that in our own code. Thanks for sharing!

@sdaly31 We had trouble with a base 64 image too. In the end we just used a URL link to an online image instead. But it would be good to get a fix for the base 64 issue.