gpt4 book ai didi

android - 如何使用 NativeScript 收听传入的短信?

转载 作者:太空狗 更新时间:2023-10-29 13:08:32 27 4
gpt4 key购买 nike

我想收听 RECEIVE_SMS Intent ,以在 Nativescript(使用 Angular2)中读取通过短信发送的一次性密码。我正在按照 http://docs.nativescript.org/cookbook/application 中概述的步骤进行操作.但是,当我运行代码时出现以下错误:

app/app.component.ts(12,6): error TS1005: ';' expected.
app/app.component.ts(12,14): error TS1005: ';' expected.
app/app.component.ts(12,48): error TS1005: ',' expected.
app/app.component.ts(12,57): error TS1005: ',' expected.
app/app.component.ts(12,67): error TS1005: ',' expected.
app/app.component.ts(12,82): error TS1138: Parameter declaration expected.
app/app.component.ts(12,118): error TS2503: Cannot find namespace 'android'.
app/app.component.ts(12,151): error TS2503: Cannot find namespace 'android'.
app/app.component.ts(13,36): error TS2304: Cannot find name 'android'.
app/app.component.ts(14,36): error TS2304: Cannot find name 'android'.
app/app.component.ts(17,4): error TS1128: Declaration or statement expected.
app/app.component.ts(18,1): error TS1128: Declaration or statement expected.

这是我的 app.component.ts:

import { Component } from "@angular/core";

@Component({
selector: "my-app",
template: `
<ActionBar title="My App"></ActionBar>
<!-- Your UI components go here -->
`
})
export class AppComponent {
// Your TypeScript logic goes here
app.android.registerBroadcastReceiver(android.provider.Telephony.SMS_RECEIVED, function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) {
console.log('rcvd');
});
}

最佳答案

看起来你没有导入所需的模块

import { Component, OnInit } from "@angular/core";
import * as app from "tns-core-modules/application";
import * as platform from "tns-core-modules/platform";

//declare this to use android variable
declare var android:any;

@Component({
selector: "my-app",
template: `
<ActionBar title="My App"></ActionBar>
<!-- Your UI components go here -->
`
})
export class AppComponent{

ngOnInit(){
app.android.registerBroadcastReceiver(android.provider.Telephony.SMS_RECEIVED, function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) {
console.log('rcvd');
});}
}

关于android - 如何使用 NativeScript 收听传入的短信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44218256/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com