Allows you to block calls in nativescript on android platform only.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
demo
publish
src
.gitignore
.travis.yml
LICENSE
README.md
tslint.json

README.md

NativeScript CallBlock

Build Status NPM version Downloads TotalDownloads Twitter Follow

Allows you to block calls in nativescript on android platform only.

Note: This documentation is not completed and will definitely update in future

Supported Plaforms:

  • Android

Installation

Install the package using any of these.

Via NPM:

tns plugin add nativescript-callblock

Via NPM:

npm install nativescript-callblock --save

Via Yarn:

yarn add nativescript-callblock

Usage: Android

Permissions:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />

JavaScript:

Create a CallBlocker.js file in the app folder of your project. Paste the following

const TelephonyManager = android.telephony.TelephonyManager;
const CallBlock = require('nativescript-callblock').CallBlock;

const NSCB = new CallBlock();

android.content.BroadcastReceiver.extend("com.tns.broadcastreceivers.CallBlocker", 
    {
        onReceive: function(context, intent) {
            var action = intent.getAction();
            number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
            
            console.log("incoming from", number);

            // Whatever you want.
            let blocked = "00000000";
            
            if(number === blocked) {
                NSCB.blockCall(context, intent);
            }

        }
    }
);

After that add reciever at the end of <application> tag in AndroidManifest.xml.

<application ... />
    ...
	<receiver
		android:name="com.tns.broadcastreceivers.CallBlocker"
		android:enabled="true"
		android:exported="true">
		<intent-filter>
			<action android:name="android.intent.action.PHONE_STATE" />
			<action android:name="android.intent.action.NEW_OUTGOING_CALL" />
		</intent-filter>
	</receiver>
</appliction>

You're good to go.