nativeScript-callblock
此插件允许您在电话响起之前阻止来电。
npm i --save nativescript-callblock

NativeScript CallBlock

Build Status NPM version Downloads TotalDownloads Twitter Follow

仅允许在Android平台上阻止nativescript中的来电。

注意:本文档尚未完成,并将肯定在未来更新

支持平台

  • Android

安装

使用以下任何一种方法安装软件包。

通过NPM

tns plugin add nativescript-callblock

通过NPM

npm install nativescript-callblock --save

通过Yarn

yarn add nativescript-callblock

使用:Android

权限

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

JavaScript

在您的项目中的app文件夹中创建一个CallBlocker.js文件。粘贴以下内容

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);
            }

        }
    }
);

之后,将接收器添加到AndroidManifest.xml中的<application>标签的末尾。

<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>

您就可以开始了。