react-native-share-menu
react-native-share-menu copied to clipboard
How to include URL webpage title in share
Is there a way to include the URL webpage title in the share intent data that is shared with app?
Depends on the app that is sharing the URL, if it includes extra data besides the URL or not. You can check if Intent.EXTRA_SUBJECT
is set.
I'm sharing the URL from a mobile browser chrome for example. Would the webpage title be in Intent.Extra_Subject? Or do I need to parse the title and put it in extra_subject by editing the react-native-share-menu plugin?
You need to modify the module anyway. You should check if the title is in Intent.EXTRA_SUBJECT
, around here: https://github.com/meedan/react-native-share-menu/blob/master/android/src/main/java/com/meedan/ShareMenuModule.java#L54, by adding a line like String title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
. Then you can pass the title
variable over to the successCallback
. If it works, it would be great if you can submit a PR :)
So something like this? if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { String input = intent.getStringExtra(Intent.EXTRA_TEXT); String title = intent.getStringExtra(Intent.EXTRA_SUBJECT); successCallback.invoke(input, title);
Yes! on the callback side, please make sure that title
is not mandatory.
Any recommendations on how I would ensure it's not mandatory?
I mean, just make sure that the callback still works if the title is not present.
With this adaptation of the .getSharedText function, the value of "title" is undefined after share action from browser (but perhaps there's something wrong with the way I added "title: string" ?):
ShareMenu.getSharedText((text: string, title: string) => { console.log("shared data is: " + text + " and " + title) if (text && text.length) { var share = { link: text, comment: title }; that.props.navigation.navigate("AndroidShareScreen", { share: share }); } });
Probably not set by the browser then :(
Is there a way to get the title of the webpage? In javascript this is quite simple. It must be possible on Android!
A possible hack is to load the URL you receive in a hidden WebView and get the title from inside it:
handleMessage(message) {
// message.nativeEvent.data contains the page title
console.log(message.nativeEvent.data);
}
render() {
return (
<WebView
source={{ uri: "put here the URL from the intent" }}
injectedJavaScript="window.postMessage(document.title)"
onMessage={this.handleMessage}
/>
)
}
Ah, good idea. I'll try it.
Oh, but this will create delay in the display of the webpage title. So it will be necessary to pass the URL to a view that invisibly loads the page completely to get the title, and then invisibly loads another view that displays the Title and the URL allowing the user to confirm what they wanted to share. Seems very complicated for a simple share action :(
Yeah, any approach to get the title from the target app side will have a delay because you'll need to basically load the URL again... that's why in the first place I suggested to try to see if the source app provides the title already... too bad it doesn't :(
Thank a lot for your help! I can't believe Chrome doesn't provide the webpage title to the share action. Sheesh.
You're welcome, good luck. If you find another solution please update here.
Hmm. According to this, the title should be included by Chrome: https://paul.kinlan.me/parsing-screenshot-from-chrome-for-android-send-intent/
Ok, so it does grab the title and the URL. I just can't get both through the callback with successCallback.invoke(input, title). Any suggestions on how to get two values through the callback?
Passing an Array to the callback doesn't seem to work. Admittedly I'm not very familiar with Java...
if (Intent.ACTION_SEND.equals(action) && type != null) {
if ("text/plain".equals(type)) {
String input = intent.getStringExtra(Intent.EXTRA_TEXT);
String title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
String[] values = {input, title};
successCallback.invoke(values);
Reopening and labeling as "feature".
i ve used this package react-native-receive-sharing-intent
Hello @ajith-ab it looks that the package that you claim to be using is actually your own creation. Sounds like a disingenuous way to advertise for your module, by tagging every open issue here! It's also a pity you chose to create your own package from scratch, instead of contributing to an existing one.
Hello @infojunkie I commented here due to this package cannot be updating by the Author and this package is only available for image and text. I have written package is Supports file, image & text share receiving . So here i will Commented here. I have created a package from scratch @infojunkie please compare this two packages
Did anyone find the solution here? I need to extract the URL and Title from the browser after sharing selected text.
Thanks in advance!
just put these lines
//keys final String EXTRA_DATA_KEY = "extra"; //created new vri for extra
if (Intent.ACTION_SEND.equals(action)) { if ("text/plain".equals(type)) { data.putString(DATA_KEY, intent.getStringExtra(Intent.EXTRA_TEXT));
//add this line
data.putString(EXTRA_DATA_KEY,intent.getStringExtra(Intent.EXTRA_SUBJECT));
return data;
}
I hope this will be helpful for you
, connect with me on Linkedin jayesh karma