添加加速度计插件时,出现以下错误
ERROR Error: Could not get foregroundActivity.
JS: ERROR Error: Could not get foregroundActivity.
ActivityManager: getContentProviderImpl: from caller=android.app.ApplicationThreadProxy@d16840e (pid=4838, userId=0) to get content provider settings cpr=ContentProviderRecord{669df61 u0 com.android.providers.settings/.SettingsProvider}
我已经删除了该插件,然后再次添加了它,删除了平台,它也不起作用
import { Component, OnInit , NgZone, OnDestroy} from "@angular/core";
import { Item } from "./item";
import { ItemService } from "./item.service";
import * as accelerometer from 'nativescript-accelerometer';
@Component({
selector: "ns-items",
moduleId: module.id,
templateUrl: "./items.component.html"
})
export class ItemsComponent implements OnInit , OnDestroy {
items: Array<Item>;
// This pattern makes use of Angular’s dependency injection implementation to
// inject an instance of the ItemService service into this class.
// Angular knows about this service because it is included in your app’s main NgModule,
// defined in app.module.ts.
constructor(private itemService: ItemService , private zone: NgZone) { }
ngOnInit(): void {
//this.items = this.itemService.getItems();
this.accelerate();
}
private accelerate(): void {
accelerometer.startAccelerometerUpdates(function(data) {
console.log("x: " + data.x + "y: " + data.y + "z: " + data.z);
}, { sensorDelay: "ui" });
}
/* private round(value, precision) {
var multiplier = Math.pow(10, precision || 0);
return Math.round(value * multiplier) / multiplier;
}*/
ngOnDestroy() {
accelerometer.stopAccelerometerUpdates();
}
}