如何解决NativeScript找不到名称“ android”
因此,我有一个NativeScript项目,我想在其中使用振动。为此,我需要访问android API。由于不建议使用NativeScript 7 tns-platform-declarations
,因此我使用@nativescript/types
。在tns-platform-declarations
的说明中,您需要一个references.d.ts
文件。我已将导入内容更新为@nativescript/types
。看起来像这样:
/// <reference path="./node_modules/@nativescript/types-ios/index.d.ts" />
/// <reference path="./node_modules/@nativescript/types-android/lib/android-26.d.ts" />
由于新的触觉API,我在这里需要android-26。在Visual Studio Code中,一切正常,AppComponent
中的代码如下所示。
import { Component,OnInit } from '@angular/core';
import { Application } from '@nativescript/core';
import { AppSettingsService } from './services/appsettings/app-settings.service';
@Component({
selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
constructor(private appSettingsService: AppSettingsService) {
}
ngOnInit() {
this.appSettingsService.vibrator = Application.android.context.getSystemService(android.content.Context.VIBRATOR_SERVICE);
if (this.appSettingsService.vibrator) {
this.appSettingsService.hasAmplitude = this.appSettingsService.vibrator.hasAmplitudeControl();
}
this.appSettingsService.vibrator.vibrate(android.os.VibrationEffect.createOneShot(1000,255));
}
}
我得到的错误是这样的。
ERROR in src/app/app.component.ts:17:85 - error TS2304: Cannot find name 'android'.
17 this.appSettingsService.vibrator = Application.android.context.getSystemService(android.content.Context.VIBRATOR_SERVICE);
~~~~~~~
src/app/app.component.ts:21:46 - error TS2304: Cannot find name 'android'.
21 this.appSettingsService.vibrator.vibrate(android.os.VibrationEffect.createOneShot(1000,255));
~~~~~~~
我在做什么错?我已经安装了@nativescript/types
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。