• Stars
    star
    409
  • Rank 102,499 (Top 3 %)
  • Language
    Java
  • Created over 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Native Android module to use Android's Intent actions for send text to shareable apps or make phone calls or opening third party apps

react-native-send-intent

React Native Android module to use Android's Intent actions for send text to shareable apps or make phone calls or opening third party apps.

npm version npm downloads npm licence donate

This module is useful when you need to share some text between apps in Android device and if you have a valid phone number make some call directly (if you ask for permission in AndroidManifest.xml).

E.g.: You have and short text and want to share in a SMS or Whatsapp.

Installation

npm install react-native-send-intent --save

Add it to your android project

  • Automatically with:
react-native link react-native-send-intent

Manually

  • In android/setting.gradle
...
include ':RNSendIntentModule', ':app'
project(':RNSendIntentModule').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-send-intent/android')
  • In android/app/build.gradle
...
dependencies {
    ...
    compile project(':RNSendIntentModule')
}
  • Register Module (in MainApplication.java)
import com.burnweb.rnsendintent.RNSendIntentPackage;  // <--- import

public class MainApplication extends Application implements ReactApplication {
  ......

  @Override
  protected List<ReactPackage> getPackages() {
    return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new RNSendIntentPackage()); // <------ add this line to your MainApplication class
  }

  ......

}

Example / Usage of Text (Share)

var SendIntentAndroid = require("react-native-send-intent");

SendIntentAndroid.sendText({
  title: "Please share this text",
  text: "Lorem ipsum dolor sit amet, per error erant eu, antiopam intellegebat ne sed",
  type: SendIntentAndroid.TEXT_PLAIN,
});

Example / Usage of Send Mail (text/plain only)

var SendIntentAndroid = require("react-native-send-intent");

SendIntentAndroid.sendMail("[email protected]", "Subject test", "Test body");

Example / Usage of SMS

Thanks to @pedro ;)

var SendIntentAndroid = require("react-native-send-intent");

SendIntentAndroid.sendSms("+55 48 9999-9999", "SMS body text here");

Example / Usage of Phone Calls

It's very important ask for permission in your AndroidManifest.xml file if you need to use Phone Calls directly. You can add an optional second parameter, to fix the default phone app.

Please add this line to your AndroidManifest.xml before using this example:

<uses-permission android:name="android.permission.CALL_PHONE" />

And them you can call in your JavaScript files:

var SendIntentAndroid = require("react-native-send-intent");

SendIntentAndroid.sendPhoneCall("+55 48 9999-9999", true);

Example / Usage of Phone Dial Screen

For this use you doesn't need to ask any permission. You can add an optional second parameter, to fix the default phone app.

var SendIntentAndroid = require("react-native-send-intent");

SendIntentAndroid.sendPhoneDial("+55 48 9999-9999", false);

Example / Create Calendar Event

According to Google using Intents for inserting, updating, and viewing calendar events is the preferred method. At this time only simple recurrence is supported ['daily'|'weekly'|'monthly'|'yearly'].

Create a Calendar Event:

// Create the Calendar Intent.
SendIntentAndroid.addCalendarEvent({
  title: "Go To The Park",
  description: "It's fun to play at the park.",
  startDate: "2016-01-25 10:00",
  endDate: "2016-01-25 11:00",
  recurrence: "weekly",
  location: "The Park",
});

Example / Check if an application is installed

Check if Gmail app is intalled. Returns a promise with a boolean telling if the app is installed or not.

SendIntentAndroid.isAppInstalled("com.google.android.gm").then(isInstalled => {});

Example / Install a remote APK

This can be used to upgrade your APK from a custom source or install other apps. No additional permissions are required.

SendIntentAndroid.installRemoteApp("https://example.com/my-app.apk", "my-saved-app.apk").then(installWasStarted => {});

Example / Open App

Open Gmail app. Returns a promise with a boolean telling if the app was opened or not:

SendIntentAndroid.openApp("com.google.android.gm").then(wasOpened => {});

// You can also specify arbitrary intent extras to be passed to the app
SendIntentAndroid.openApp("com.mycorp.myapp", {
  "com.mycorp.myapp.reason": "just because",
  "com.mycorp.myapp.data": "must be a string",
}).then(wasOpened => {});

Example / Open App with Data

Opens MX Player (Free) app and starts a video at the 1 minute mark. Returns a promise with a boolean telling if the app was opened or not:

SendIntentAndroid.openAppWithData(
  "com.mxtech.videoplayer.ad",
  "http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi",
  "video/*",
  {
    position: { type: "int", value: 60 },
  }
).then(wasOpened => {});

Example / Open Chrome Intent

Opens Chrome intent as defined in https://developer.chrome.com/multidevice/android/intents

Returns a promise with a boolean.

True if: the intent was handled by an activity or the browser opened the browser_fallback_url

False if both conditions are not fulfilled

SendIntentAndroid.openChromeIntent("intent://www.spm.com/qrlogin#Intent;scheme=https;package=example.package;S.browser_fallback_url=https://www.spm.com/download;end",
  }
).then((wasOpened) => {});

Example / Open Calendar

SendIntentAndroid.openCalendar();

Example / Open Camera Intent

SendIntentAndroid.openCamera();

Example / Open Email Application

Will open default Email application

SendIntentAndroid.openEmailApp();

Will open all the Email app's that available in device

SendIntentAndroid.openAllEmailApp();

Example / Open Download Manager

SendIntentAndroid.openDownloadManager();

Example / Open Share With dialog

Opens Androids default share tray:

// Create Share With dialog.
SendIntentAndroid.openChooserWithOptions(
  {
    subject: "Story Title",
    text: "Message Body",
  },
  "Share Story"
);

SendIntentAndroid.openChooserWithOptions(
  {
    subject: "Video Title",
    videoUrl: "/path_or_url/to/video.mp4",
  },
  "Share video to"
);

Example / Open Multiple Files Share With dialog

Opens Androids default share tray:

// Create Multiple Files Share With dialog.
SendIntentAndroid.openChooserWithMultipleOptions(
  [
    {
      subject: "Video One Title",
      videoUrl: "/path_or_url/to/video.mp4",
    },
    {
      subject: "Video Two Title",
      videoUrl: "/path_or_url/to/video2.mp4",
    },
  ],
  "Share videos to"
);

SendIntentAndroid.openChooserWithMultipleOptions(
  [
    {
      subject: "Video Title",
      text: "Test shared with video",
    },
    {
      subject: "Video Title",
      videoUrl: "/path_or_url/to/video.mp4",
    },
  ],
  "Share video to"
);

Example / Open Maps

Opens Androids default maps app with location:

// Open Maps App
SendIntentAndroid.openMaps("Piccadilly Circus Station, London, United Kingdom");

Example / Open Maps With Route

Opens Androids default maps app, and route path between your location and address:

mode: d,w,b

  • d: drive car
  • w: walking
  • b: bicycle
SendIntentAndroid.openMapsWithRoute("Piccadilly Circus Station, London, United Kingdom", "w");

Example / Share text to line

SendIntentAndroid.isAppInstalled("jp.naver.line.android").then(function (isInstalled) {
  if (!isInstalled) {
    //LINE has not install, you need to install it!
    return;
  }

  SendIntentAndroid.shareTextToLine({ text: "txt message that you want to share" });
});

When you call SendIntentAndroid.shareTextToLine this method, app will bring txt message to LINE, and you can select one or multiple friends to share.

Example / Share Image to Instagram

import { CameraRoll } from "react-native";

//get frist image from CameraRoll
CameraRoll.getPhotos({ first: 1 }).then(
  function (data) {
    const assets = data.edges;

    SendIntentAndroid.isAppInstalled("com.instagram.android").then(function (isInstalled) {
      if (!isInstalled) {
        //Instagram has not install
        return;
      }

      SendIntentAndroid.shareImageToInstagram("image/*", encodeURI(assets[0].node.image.uri));
    });
  },
  function (err) {
    console.error("An error occurred", err);
  }
);

Share your first image from CameraRoll to Instagram.

Example / Open Settings

Opens a specified settings screen when passed one of the constant values available in android.provider.settings (use the constant value found here to open the Security Settings screen).

SendIntentAndroid.openSettings("android.settings.SECURITY_SETTINGS");

Example / Get voiceMail number

Please add this line to your AndroidManifest.xml file before using next example:

  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
SendIntentAndroid.getVoiceMailNumber().then(voiceMailNumber => {
  if (!voiceMailNumber) {
    return console.error("Can`t get voiceMailNumber");
  }

  //if u want to use next line, u need to add CALL_PHONE permission
  SendIntentAndroid.sendPhoneCall(voiceMailNumber);
});

Example / Open File Chooser

Opens Android chooser so the user can select which app will handle the file.

SendIntentAndroid.openFileChooser(
  {
    subject: "File subject", //optional,
    fileUrl: "/path_or_url/to/file",
    type: "file_mimetype",
  },
  "Open file with:"
);

Example / Open File Picker

Opens Android own file selector to get the selected file and callback path from Uri

SendIntentAndroid.openFilePicker(
  {
    type: "file_mimetype", //default is "*/*"
    title: "selector title", //default is "Choose File"
  },
  filePath => {}
);

Example / Get phone number

Please add these lines to your AndroidManifest.xml file before using next example:

  <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  <uses-permission android:name="android.permission.READ_PHONE_NUMBERS" />
SendIntentAndroid.getPhoneNumber().then(phoneNumber => {
  if (!phoneNumber) {
    return console.error("Can`t get phoneNumber");
  }

  //do something with number
});

Example / Request 'ignore battery optimizations'

Please add this line to your AndroidManifest.xml file before using next example:

  <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>

Prompts the user to add your app to the Doze and App Standby optimizations exception white-list. Returns true if running on Android version M and greater, if the app is not on the white-list, and the intent was successfully shown. Will only show on Android version M and greater. For more details look here.

SendIntentAndroid.requestIgnoreBatteryOptimizations().then(intentShown => {});

Example / Show battery optimizations settings

Will only show on Android version M and greater. For more details look here.

SendIntentAndroid.showIgnoreBatteryOptimizationsSettings();

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

paypal

License

MIT

More Repositories

1

react-native-flash-message

React Native flashbar and top notification alert utility
JavaScript
1,344
star
2

react-native-webview-android

Simple React Native Android module to use Android's WebView inside your app
Java
357
star
3

react-native-android-permissions

React Native Android Permissions experimental module - Android M (6.0) permissions like to your React Native application
Java
119
star
4

react-async-fetcher

React component for asynchronous loading/fetch online data
JavaScript
50
star
5

react-native-simpledialog-android

React Native Android module to use Android's AlertDialog - same idea of AlertIOS
Java
43
star
6

react-virtualized-sectionlist

React SectionList component based in react-virtualized List
JavaScript
20
star
7

cakephp-amazonses

EmailServiceComponent to send e-mail using Amazon SES
PHP
6
star
8

react-native-progress-indicator

React Native cross-plataform module to create Progress Indicators in your apps
JavaScript
6
star
9

flythat

A simple powerful jQuery plugin to help create modals, flyovers or light-popups in your web project
JavaScript
5
star
10

react-native-platform-render

React Native swiss army knife tools to platform conditional render
JavaScript
4
star
11

cakephp-sluggable

Sluggable Behavior for CakePHP
PHP
2
star
12

db-migr

Javascript db migrations utility for SQLite, MySQL or other SQL Ansi databases
JavaScript
2
star
13

sw-php-laravel

Aula de Soluรงรตes WEB do Curso de Eng. Comp. da SATC - Exemplo de projeto com Laravel
PHP
2
star
14

slides-sw-aula-01

JavaScript
1
star
15

node-use-phpfmt

A simpler phpfmt installer for Node.js work
JavaScript
1
star
16

slides-sw-aula-07

HTML
1
star
17

slides-sw-aula-08

CSS
1
star
18

cakephp-uploader

Uploader Behavior for CakePHP
PHP
1
star
19

slides-front-end-aula-01

TypeScript
1
star