Giter Club home page Giter Club 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.

npm version npm downloads npm licence

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

  • 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 >= 0.18 (in MainActivity.java)
import com.burnweb.rnsendintent.RNSendIntentPackage;  // <--- import

public class MainActivity extends ReactActivity {
  ......

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

  ......

}
  • Register Module <= 0.17 (in MainActivity.java)
import com.burnweb.rnsendintent.RNSendIntentPackage;  // <--- import

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
  ......

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mReactRootView = new ReactRootView(this);

    mReactInstanceManager = ReactInstanceManager.builder()
      .setApplication(getApplication())
      .setBundleAssetName("index.android.bundle")
      .setJSMainModuleName("index.android")
      .addPackage(new MainReactPackage())
      .addPackage(new RNSendIntentPackage()) // <------ add this line to your MainActivity class
      .setUseDeveloperSupport(BuildConfig.DEBUG)
      .setInitialLifecycleState(LifecycleState.RESUMED)
      .build();

    mReactRootView.startReactApplication(mReactInstanceManager, "AndroidRNSample", null);

    setContentView(mReactRootView);
  }

  ......

}

Example / Usage of Text

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 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.

Please add this line to your 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');

Example / Usage of Phone Dial Screen

For this use you doesn't need to ask any permission.

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

SendIntentAndroid.sendPhoneDial('+55 48 9999-9999');

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 / Open Calendar

SendIntentAndroid.openCalendar();

License

MIT

react-native-send-intent's People

Contributors

asommer70 avatar ciklop avatar hosoi-appland avatar isair avatar lucasferreira avatar sonnylazuardi avatar thevaffel avatar zidail avatar

Watchers

 avatar  avatar

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.