Giter Site home page Giter Site logo

giovannibattista / cordova-calllog-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dalyc/cordova-calllog-plugin

0.0 2.0 0.0 381 KB

Android only (help with IOS welcome) cordova plugin to access the call history on a device.

Java 87.25% JavaScript 12.75%

cordova-calllog-plugin's Introduction

Cordova-CallLog-Plugin

Android only (help with IOS welcome) cordova plugin to access the call history on a device.

Installation

cordova plugins add "https://github.com/dalyc/Cordova-CallLog-Plugin"

Permissions

Add the following permissions to your AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CALL_LOG" />
<uses-permission android:name="android.permission.READ_CONTACTS" />

Usage

I've only used this in an Ionic application so this usage is AngularJS based. Here is my CallLogService accessing the plugin (window.plugins.calllog)

.factory('CallLogService', ['$q', function($q) {
    return {

        list : function(days) {
            var q = $q.defer();
            // days is how many days back to go
            window.plugins.calllog.list(days, function (response) {
                q.resolve(response.rows);
            }, function (error) {
                q.reject(error)
            });
            return q.promise;
        },

        contact : function(phoneNumber) {
            var q = $q.defer();
            window.plugins.calllog.contact(phoneNumber, function (response) {
                q.resolve(response);
            }, function (error) {
                q.reject(error)
            });
            return q.promise;
        },

        show : function(phoneNumber) {
            var q = $q.defer();
            window.plugins.calllog.show(phoneNumber, function (response) {
                q.resolve(response);
            }, function (error) {
                q.reject(error)
            });
            return q.promise;
        }

        delete : function(phoneNumber) {
            var q = $q.defer();
            window.plugins.calllog.delete(id, function (response) {
                q.resolve(response);
            }, function (error) {
                q.reject(error)
            });
            return q.promise;
        }
    }
}])

Here is a controller using the above service

.controller('DebugCtrl', ['$scope', 'CallLogService', 'LocalStorage',
    function ($scope, CallLogService, LocalStorage) {

        $scope.data = {};
        $scope.callTypeDisplay = function(type) {
            switch(type) {
                case 1:
                    return 'Incoming';
                case 2:
                    return 'Outgoing';
                case 3:
                    return 'Missed';
                default:
                    return 'Unknown';
            }
        };

        CallLogService.list(1).then(
            function(callLog) {
                console.log(callLog);
                $scope.data.lastCall = callLog[0];
            },
            function(error) {
                console.error(error);
            });
    }]);

Here is my debug.html view that calls the above controller.

<ion-view class="h6" title="Debug">
    <ion-content class="has-header">
        <div class="row">
            <div class="col">Last Call</div>
        </div>
        <div class="row">
            <div class="col col-30 col-offset-10">Name</div>
            <div class="col">{{data.lastCall.cachedName}}</div>
        </div>
        <div class="row">
            <div class="col col-30 col-offset-10">Number</div>
            <div class="col">{{data.lastCall.number}}</div>
        </div>
        <div class="row">
            <div class="col col-30 col-offset-10">Type</div>
            <div class="col">{{callTypeDisplay(data.lastCall.type)}}</div>
        </div>
        <div class="row">
            <div class="col col-30 col-offset-10">Date</div>
            <div class="col">{{data.lastCall.date | date}}</div>
        </div>
        <div class="row">
            <div class="col col-30 col-offset-10">Duration</div>
            <div class="col">{{data.lastCall.duration}} seconds</div>
        </div>
        <div class="row">
            <div class="col col-30 col-offset-10">Acknowledged</div>
            <div class="col">{{(data.lastCall.new == 1 ? 'yes' : 'no')}}</div>
        </div>
    </ion-content>
</ion-view>

Note that I also have a decorator in app.js to allow my app to continue working when testing in a browser

$provide.decorator('CallLogService', ['$delegate', '$q', function ($delegate, $q) {
  if (window.plugins && window.plugins.calllog) {
    return $delegate;
} else {
    return {
      list : function() {
        var lastCall = {
          cachedName: 'Joe Blow',
          cachedNumberType: 2,
          date: 1406720317112,
          duration: 2224,
          new: 1,
          number: '0420884679',
          type: 1
        };
        return $q.when([lastCall]);
      },
      contact : function() {
        return $q.when({});
      },
      show : function() {
        return $q.when(true);
      }
    };
  }
}]);

cordova-calllog-plugin's People

Contributors

dalyc avatar tfkamran avatar

Watchers

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