Share URL to facebook on Android

#1

How to share text & url to facebook on Android? React Native allows us to share url on iOS but not for Android. Please help!

#2

Here it is :wink:

I did it for both system and the doc says:

> Open a dialog to share text content.

> In iOS, Returns a Promise which will be invoked an object containing action, activityType. If the user dismissed the dialog, the Promise will still be resolved with action being Share.dismissedAction and all the other keys being undefined.

> In Android, Returns a Promise which always be resolved with action being Share.sharedAction.

#3

How did you get it to work on Android? Only works on iOS for me as well.

#4

I actually didn’t test on IOS by myself (I need a macbook :sweat_smile:), but it seems to works on both system.
I did like this:

import React, { Component } from 'react';
import {
  View,
  Share,
  TouchableOpacity,
  Platform
} from 'react-native';
import { Icon } from 'react-native-elements';

class SharingItem extends Component {

  onClick() {
    Share.share({
      ...Platform.select({
        ios: {
          message: 'Have a look on : ',
          url: this.props.url,
        },
        android: {
          message: 'Have a look on : \n' + this.props.url
        }
      }),
      title: 'Wow, did you see that?'
    }, {
      ...Platform.select({
        ios: {
          // iOS only:
          excludedActivityTypes: [
            'com.apple.UIKit.activity.PostToTwitter'
          ]
        },
        android: {
          // Android only:
          dialogTitle: 'Share : ' + this.props.title
        }
      })
    });
  }

  render() {
    return (
      <View>
        <TouchableOpacity
          onPress={() => { this.onClick(); }}
        >
        <Icon
          key={this.props.keyId}
          name='share-alt'
          type='font-awesome'
          color='#22313F'
          size={22}
        />
        </TouchableOpacity>
      </View>
    );
  }
}

export default SharingItem;
6 Likes
#5

Ahh, i see now the URL attribute only works on ios.

Thanks

#6

Cool if it’s helped you :slightly_smiling_face:

Cheers :wink:

1 Like
#7

I worked now, thanks a lot!

1 Like
#8

Cool, happy that’s helped you :wink:

#9

Can you help me with, coding share message in such a way that the whatsapp will render the image and title and message.
For example.
47%20AM

Note: I don’t have dynamic detail page like github

1 Like
closed #11

This topic was automatically closed after 14 days. New replies are no longer allowed.