nativescript-sms-inbox
by jgithaiga | v2.1.0
使用未公开的安卓API在安卓手机收件箱中读取文本消息。
npm i --save nativescript-sms-inbox

npm npm

NativeScript Sms Inbox

一个使用未公开的安卓API在安卓手机收件箱中读取文本消息的NativeScript插件。

安装

使用NativeScript CLI工具安装插件

tns plugin add nativescript-sms-inbox

Android

要在安卓手机上读取短信收件箱且不与用户交互,您的应用必须请求权限。以下内容必须添加到您的应用的AndroidManifest.xml

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

使用方法

要使用电话模块,您必须首先从项目的node_modules目录使用require()引入它

var inbox = require( "nativescript-sms-inbox" );

在您获得模块引用后,您可以调用可用的方法。

方法

getInboxes: 获取收件箱中的所有文本消息

参数
  • options: 参数的映射,例如 max(用于最大结果)等。

例如,以下代码从设备收件箱中获取最后10条短信

// my-page.js
var inbox = require( "nativescript-sms-inbox" );
inbox.getInboxes({ max: 10 }).then(function(res) {
console.log(JSON.stringify(res));
}, function(err) {
console.log("Error: " + err);
});

getInboxesFromNumber: 获取由提供的fromNumber发送的所有短信收件箱中的文本消息

参数
  • fromNumber - 要过滤短信收件箱消息的号码。
  • options - 参数的映射,例如 max(用于最大结果)等。

例如,以下代码从设备收件箱中获取由提供的fromNumber发送的最后10条短信

// my-page.js
var inbox = require( "nativescript-sms-inbox" );
inbox.getInboxesFromNumber("0712345678", { max: 10 }).then(function(res) {
console.log(JSON.stringify(res));
}, function(err) {
console.log("Error: " + err);
});

TypeScript示例


import * as TNSInbox from 'nativescript-sms-inbox';

// Get the last 10 inbox messages
public getInboxMessages() {
TNSInbox.getInboxes({ max: 10 }).then((res) => {
console.log(JSON.stringify(res))
;
}, (err) => {
console.log('Error: ' + err);
});
}

// Get the last 10 inbox messages sent by the provided fromNumber
public getInboxMessagesFromNumber(fromNumber: string) { //fromNumber = "0712345678"
TNSInbox.getInboxesFromNumber(fromNumber, { max: 10 }).then((res) => {
console.log(JSON.stringify(res))
;
}, (err) => {
console.log('Error: ' + err);
});
}