nativescript-callblock
v0.0.2
Published
This plugin allows you to block calls before ringing.
Downloads
2
Maintainers
Readme
NativeScript CallBlock
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.