Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.

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

License

Notifications You must be signed in to change notification settings

SalehMahmood/nativescript-callblock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published