Giter VIP home page Giter VIP logo

react-native-send-intent's Introduction

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

react-native-send-intent's People

Contributors

1uokun avatar adamivancza avatar andrew-stupchuk avatar asommer70 avatar bradser avatar bradserbuddy avatar chipshort avatar ciklop avatar finalevil avatar gamoridev avatar hosoi-appland avatar japjappedulap avatar jberendes avatar jeaye avatar jihoon-rpls avatar jsamr avatar julioaugustos avatar lucasferreira avatar maraujop avatar misshannah avatar peterchibunna avatar radko93 avatar rafalkowalewski avatar remejuan avatar sonnylazuardi avatar thedevdavid avatar thevaffel avatar treemore avatar usrbowe avatar zidail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-send-intent's Issues

Open Storage

Hi, I would like to know if it's possible to open an specific path on Storage Directory.

SendIntentAndroid.sendPhoneCall not working for me

Hi, gj by the way!

I need to call to a number without exiting my app and if I use
SendIntentAndroid.sendPhoneCall('+55 48 9999-9999');
it shows up the phone dial, and If I add the 2nd parameter
SendIntentAndroid.sendPhoneCall('+55 48 9999-9999', true);
nothing happens... what am I doing wrong?

I added the on AndroidManifest.xml

Thanks for the help and merry xmas!

Crash when adding calendar event

I get an edge-case crash when adding a calendar event (device was reported as an un-rooted LENNY3 in Europe):

Fatal Exception: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.INSERT dat=content://com.android.calendar/events flg=0x10000000 (has extras) }
       at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1809)
       at android.app.Instrumentation.execStartActivity(Instrumentation.java:1523)
       at android.app.ContextImpl.startActivity(ContextImpl.java:682)
       at android.app.ContextImpl.startActivity(ContextImpl.java:664)
       at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
       at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)
       at com.burnweb.rnsendintent.RNSendIntentModule.addCalendarEvent(RNSendIntentModule.java:190)

Strange, since the sendintent code is checking resolveActivity. I suspect it's an instance of https://stackoverflow.com/questions/22479211/intent-resolveactivity-null-but-launching-the-intent-throws-an-activitynotfou , since not sure how else this could happen.

Version iOS

Hi my friend!

It would be interesting to make the version for iOS too, I can share the knowledge to create the version for iOS and adapt to the one that has for Android.

Sharing pdf file

I have seen openChooserWithMultipleOptions and I want to share pdf files. Is there any way I can do that?

Question - Install then Open (remote apk)?

I have an apk that is in development, not in the store, and I am invoking from a screen in another of another as-yet not-in-store app.
When I call to install , it says "there was an issue parsing this app", but when i install that app independently , it runs fine.
I uploaded the second apk (the one being called to install, and hopefully open) to a server. Can I install and then open it? That doesn't seem to work with what I've tried, and time is short! Thanks.

openSettings() function should allow an optional package name

Android allows developers to open an app's settings menu directly via an Intent. This can be useful if a user has declined a permission and the dev. wants to deep link the user to their app's settings screen so the user can grant the permission. To do this a developer needs to be able to specify an intent name and a package name.

Here's an example of how a developer would need to create an intent to open an app's settings screen:
[(https://developer.android.com/reference/android/provider/Settings.html#ACTION_APPLICATION_DETAILS_SETTINGS)]

I believe an optional argument could be added to the openSettings() method in the android module that, when present, would add the package name as a uri to the intent data:

try { Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); intent.setData(Uri.parse("package:" + packageName)); startActivity(intent); } catch (ActivityNotFoundException e){ e.printStackTrace(); }

Install a remote APK not works on Android 7

i've tested this method on android 7 and react native 0.55
download started and it seems download finished but file not saved

the code i've used :
SendIntentAndroid.installRemoteApp('http://dl.apktops.ir/apps/2018/07/KillApps_Close_all_apps_running_Pro_v1.8.13_Apktops.ir.apk', 'KillApps_Close_all_apps_running_Pro_v1.8.13_Apktops.ir.apk').then((installWasStarted) => {
});`

list sms

can i list my inbox sms using this ??

sendText and sendSms not working ?

In the project you sent me earlier, i replaced the phone code with the sms one , it gave me a function not defined message.

using the text one apparently did nothing.

thanks for your help

Problem adding event to Calendar

Hello,
I am trying to add the event in you example:
// 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' });

but I have the following problem.
screenshot_20161008-002802

Any help?
Thank you in advance

Calendar events not working?!

Hey there. I am working on RN V0.20. Unfortunately i cant use

SendIntentAndroid.sendAddCalendarEvent({... 
SendIntentAndroid.sendOpenCalendar();

I get for both "undefined is not a function"? Any ideas?
I tried as well following:

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'
    });

how to know whome we are sending in code level

Hi all Thanks for nice and use full module.

Here I am using
SendIntentAndroid.sendText({})
send message to friend through watsapp.

Is it possible to know message send to how many no.of watsapp contacts like any callback response ?

Thanks.

callback after addCalendarEvent ?

Hi,

I'm able to send the Intent in order to create one calendar event: it displays me the calendar app with the filled fields, and I can, from that app, create the event. But I'd like to redirect the user to my app after the creation. Is there a way to do this?

evaluating 'RNSendIntentAndroid.TEXT_PLAIN'

Hi, I just installed this module and after importing it, I try to run the app but I got this error: undefined is not an object (evaluating 'RNSendIntentAndroid.TEXT_PLAIN'). I can't figure out why. Can someone help me?

Calling numbers that end with "#"

The trailing # in a number you want to call gets removed (in the case of ussd requests)

I've tried to replace the number with %23 but it has not worked.
Help!

More than 1 file on openChooserWithOptions

Hi, again!

Is there a way to attach more than 1 file and share they on SendIntentAndroid.openChooserWithOptions?

Like this:

SendIntentAndroid.openChooserWithOptions({
     subject: 'Video Title',
     videoUrl: { '/path_or_url/to/video1.mp4', '/path_or_url/to/video2.mp4' }
}, 'Share two videos to')

RN 0.38 error: cannot find symbol new RNSendIntentPackage()

Got this error

:app:compileDebugJavaWithJavac
C:\react\afisha5\android\app\src\main\java\com\afisha5\MainApplication.java:29:
error: cannot find symbol
new RNSendIntentPackage()
^
symbol: class RNSendIntentPackage
1 error
:app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':app:compileDebugJavaWithJavac'.

Compilation failed; see the compiler error output for details.

Any way to launch the phone?

Sorry this is not an issue, but a question for you. I haven't found a lib to launch the phone in Android/react-native yet.

Is there a way this could be extended to launch the phone? Or maybe that should be your next project (i'm using your webview component) :D :neckbeard:

Make it safe to require this module from iOS

When requiring this module from iOS codebase (that doesn't have SendIntentAndroid) "Undefined is not an object" is thrown.

var RNSendIntentAndroid = require('react-native').NativeModules.SendIntentAndroid;

var SendIntentAndroid = {
    TEXT_PLAIN: RNSendIntentAndroid.TEXT_PLAIN,  // <-- RNSendIntentAndroid is undefined
    TEXT_HTML: RNSendIntentAndroid.TEXT_HTML,
    ...
}

Please consider making it safe to require from both platforms, so that the end used doesn't have to add if (Platform.OS === 'android') { require('react-native-send-intent'); } (which will stop working if RN transitions to ES6 modules).

multiple SMS send intentions

Hello guys, I was looking to work with the SMS send intent on this lib, but looking at the implementation it seems that it can only send SMS intention to 1 phone number.

Anyone is interested in the feature of sending an SMS to multiple phone numbers?

Example:
Open the SMS message app with the text 'Hello world' and multiple phone numbers.

Getting error invoking any method

Hi! Im getting an error when i try to invoke any SendIntentAndroid function

image

This happens with any funtion, i cant understand what im doing bad. Im Just copying the example provided.

import * as SendIntentAndroid from 'react-native-send-intent'

SendIntentAndroid.openChooserWithOptions( { subject: 'Story Title', text: 'Message Body' }, 'Share Story' )

Im running this with:

"dependencies": {
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-elements": "^1.1.0",
"react-native-send-intent": "^1.0.30",
"react-native-vector-icons": "^6.4.2"
},

Many thanks in advance.

Unable to use library in Expo

RNSendIntentAndroid.openChooserWithOptions is not a function. (In 'RNSendIntentAndroid.openChooserWithOptions(options, title)', 'RNSendIntentAndroid.openChooserWithOptions' is undefined)

iPhone support?

Hi,
Thanks for all your modules!
I'm looking to subtitute react-native-share package because of missing libraries on xcode.
Do you have the ability to implement iOS support to this module?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.