4

In my react-native app, I want to share a text message with a specific application, e.g whatsapp or texting application without having to first land on the dialog with all the social applications.

For instance if I press the share button and whatsapp is called directly.

I tried using react-native-share but it seems to not be working anymore.

Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59
charles
  • 63
  • 1
  • 7
  • single or multiple images sharing using react-native-share, answer by me with more detailed info here, checkout - https://stackoverflow.com/questions/67016851/want-to-share-multiple-images-with-separate-caption-to-each-image-whatsapp-reac/67167916#67167916 – Lakshman Kambam Apr 19 '21 at 19:31

2 Answers2

6

You can use Linking, which gives you a general interface to interact with both incoming and outgoing app links.

For example:

import React, { Component } from 'react';
import { Linking, Button } from 'react-native';

export class App extends Component {
  render() {
    return <Button
              onPress={() => {
                let url = 'whatsapp://send?text=Hola Mundo';
                Linking.openURL(url).then((data) => {
                  console.log('open whatsapp')
                }).catch(() => {
                  console.log('App not installed')
                });
              }}
              title="Whatsapp"
              color="#4FBE3C"/>;
  }
}
Sebastián Palma
  • 32,692
  • 6
  • 40
  • 59
  • @sebastian I couldn't understand what should be the URL ? If I want to share pdf or jpeg files on whatsapp what will be the URL in that case ? – fun joker Oct 17 '18 at 11:36
  • I couldn't understand what should be the URL ? If I want to share pdf or jpeg files on whatsapp what will be the URL in that case ? – fun joker Oct 17 '18 at 11:36
0

For Android, the React Native Share module uses the default ACTION_SEND android intent:

Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);

In order to have a different behavior, you need either write our own RN plugin that would talk to the app you want it to (if such feature is available) or find a similar plugin on npm.

I assume your plugin should do something like this:

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
sendIntent.setPackage("com.whatsapp");
Yury
  • 161
  • 2
  • 10