veneliniliev / capacitor-plugin-incoming-call

capacitor-plugin-incoming-call

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

capacitor-plugin-incoming-call

capacitor-plugin-incoming-call

Install

install the package and sync the project.

npm install capacitor-plugin-incoming-call
npx cap sync

Add the required permissions to the Android source code

android\app\src\main\java\app\[package_namespace]\MainActivity.java

import android.os.Bundle; // required for onCreate parameter
import com.getcapacitor.BridgeActivity;
import androidx.core.app.ActivityCompat;

public class MainActivity extends BridgeActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String[] PERMISSIONS = {
      android.Manifest.permission.READ_PHONE_STATE,
      android.Manifest.permission.READ_CALL_LOG
    };

    ActivityCompat.requestPermissions(MainActivity.this,
      PERMISSIONS,
      0);
  }

}

Usage

Typescipt side changes:

console.log('### Test CallDetector plugin ###');
CallDetector.detectCallState({ action: 'ACTIVATE' }).then(x => console.log(x)).catch(e => console.error(e));
CallDetector.addListener('callStateChange', res => {
  console.log('### Listening to callStateChange ###');
  console.log(res);
});

API

echo(...)

echo(options: { value: string; }) => Promise<{ value: string; }>
Param Type
options { value: string; }

Returns: Promise<{ value: string; }>


detectCallState(...)

detectCallState(options: { action: string; }) => Promise<{ action: string; }>

To enable / disable detection of calls options: { action: 'ACTIVATE' | 'DEACTIVATE' }

Param Type
options { action: string; }

Returns: Promise<{ action: string; }>


addListener('callStateChange', ...)

addListener(eventName: 'callStateChange', listenerFunc: CallStateChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle
Param Type
eventName 'callStateChange'
listenerFunc CallStateChangeListener

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


Interfaces

PluginListenerHandle

Prop Type
remove () => Promise<void>

PhoneState

Prop Type Description Since
callActive boolean Whether there is an active call or not. 1.0.0
callState PhoneStateType The type of call. 'RINGING' | 'OUTGOING' | 'IDLE' | 'ON_CALL' | 'ON_HOLD' 1.0.0

Type Aliases

CallStateChangeListener

(status: PhoneState): void

PhoneStateType

'RINGING' | 'OUTGOING' | 'IDLE' | 'ON_CALL' | 'ON_HOLD'

About

capacitor-plugin-incoming-call


Languages

Language:Java 55.8%Language:Swift 20.0%Language:TypeScript 10.9%Language:Ruby 5.9%Language:Objective-C 4.5%Language:JavaScript 2.9%