Giter VIP home page Giter VIP logo

react-native-call-log's Introduction

call log package for android in react-native

Installation:

Run yarn add react-native-call-log

Android

React Native 0.60+

auto links the module

React Native <= 0.59

Auto

react-native link react-native-call-log

Manual

  • Edit your android/settings.gradle to look like this (exclude +)
+ include ':react-native-call-log'
+ project(':react-native-call-log').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-call-log/android')
  • Edit your android/app/build.gradle (note: app folder) to look like this (exclude +)
dependencies {
+ implementation project(':react-native-call-log')
}
  • Edit your MainApplication.java from ( android/app/src/main/java/...) to look like this (exclude +)
+ import com.wscodelabs.callLogs.CallLogPackage;

@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
+         new CallLogPackage()
      );
    }

Usage

import { PermissionsAndroid } from 'react-native';
import CallLogs from 'react-native-call-log'

 useEffect(() => {
    (async () => {
      try {
        const granted = await PermissionsAndroid.request(
          PermissionsAndroid.PERMISSIONS.READ_CALL_LOG,
          {
            title: 'Call Log Example',
            message:
              'Access your call logs',
            buttonNeutral: 'Ask Me Later',
            buttonNegative: 'Cancel',
            buttonPositive: 'OK',
          }
        )
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {

          CallLogs.load(-1, filter).then(c => console.log(c));
        } else {
          console.log('Call Log permission denied');
        }
      }
      catch (e) {
        console.log(e);
      }
    })()
  }, []);

Methods

Methods Description
load(LIMIT) LIMIT: number get maximum number of call logs.
load(limit, filter) LIMIT: number (use -1 for no limit)
filter: see usage here)
loadAll() get all call logs

Filter call logs

...
/* List call logs matching the filter */
const filter = {
  minTimestamp: 1571835032,    // (Number or String) timestamp in milliseconds since UNIX epoch
                               // if this filter is set, load(limit, filter) will only return call logs with timestamp >= minTimestamp

  maxTimestamp: 1571835033,    // (Number or String) timestamp in milliseconds since UNIX epoch
                               //
                               // if this filter is set, load(limit, filter) will only return call logs with timestamp <= maxTimestamp

  phoneNumbers: '+1234567890', // (String or an Array of String)
                               // if this filter is set, load(limit, filter) will only return call logs for this/these phone numbers

  types: 'MISSED',             // (Single value / Array of Strings / CallType enums)
                               // if this filter is set, load(limit, filter) will only return call logs of a specific type
}

const callLogs = await CallLogs.load(-1, filter) // applies filter with no limit (also works with a limit)
...

Example

Clone or download the repository then Run cd Example && npm install

react-native-call-log's People

Contributors

aathapa avatar philbot9 avatar piyushcoader avatar olivierfreyssinet-old avatar mikehardy avatar aayushgh avatar babraham123 avatar windless avatar dependabot[bot] avatar p-tsai avatar peterchibunna 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.