8

I am trying to share my app installation link to others from my app settings in react native.

I used the react native share api for this.

But using the below code the output only shows the message(code and screenshot below).

const shareAppOptions = {
  title: 'App link',
  message: 'Please install this app and stay safe', 
  url: 'https://play.google.com/store/apps/details?id=nic.goi.aarogyasetu&hl=en'
};

enter image description here

What is the problem ?, I searched everywhere and no one has a proper example.

Amal p
  • 2,882
  • 4
  • 29
  • 49

3 Answers3

9

The problem is In Android, you cant specify something as url , but the same when you do in IOS, youll get the link (Check the docs to cross verify :rn-share. Its better you can send the link of the app in the message itself so that both platforms can get it without writing double code.

Like this is the example :

import React from 'react';
import { Share, View, Button } from 'react-native';

export default ShareExample = () => {
  const onShare = async () => {
    try {
      const result = await Share.share({
       title: 'App link',
  message: 'Please install this app and stay safe , AppLink :https://play.google.com/store/apps/details?id=nic.goi.aarogyasetu&hl=en', 
  url: 'https://play.google.com/store/apps/details?id=nic.goi.aarogyasetu&hl=en'
      });
      if (result.action === Share.sharedAction) {
        if (result.activityType) {
          // shared with activity type of result.activityType
        } else {
          // shared
        }
      } else if (result.action === Share.dismissedAction) {
        // dismissed
      }
    } catch (error) {
      alert(error.message);
    }
  };
  return (
    <View style={{ marginTop: 50 }}>
      <Button onPress={onShare} title="Share" />
    </View>
  );
};

Hope it helps. feel free for doubts

Gaurav Roy
  • 11,175
  • 3
  • 24
  • 45
  • 1
    What is the link to share app on IOS ? – Josss Aug 31 '20 at 15:32
  • @Jocelin I'm sure you've figured this out by now since it's an old post, but for others that are reading this: Go into the AppStore Connect portal, click on your App, and then on "App Information" under 'General' in the left-hand nav column. Scroll all the way to the bottom and you'll see "View on App Store" under the 'Additional Information' section. This is the direct link to the app on the store. – Drew Aug 04 '21 at 17:54
5

I think you can share your app link by placing the url in the message section.

message:'https://play.google.com/store/apps/details?id=nic.goi.aarogyasetu&hl=en'

Yashovardhan99
  • 887
  • 11
  • 26
-2
import {Share} from 'react-native';

try {
  const result = await Share.share({
    message:'Your message here'
  });

  if (result.action === Share.sharedAction) {
    if (result.activityType) {
      // shared with activity type of result.activityType
    } else {
      // shared
    }
  } else if (result.action === Share.dismissedAction) {
    // dismissed
  }
} catch (error) {
  alert(error.message);
}
Syscall
  • 19,327
  • 10
  • 37
  • 52
Antier Solutions
  • 1,326
  • 7
  • 10