nativescript-callblock
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

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.

Package Sidebar

Install

npm i nativescript-callblock

Weekly Downloads

0

Version

0.0.2

License

Apache-2.0

Unpacked Size

26.6 kB

Total Files

11

Last publish

Collaborators

  • salehmahmood