- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习 ionic 5 并想创建一个简单的应用程序,该应用程序显示附近所有支持蓝牙的手机的列表。我的问题是,当我使用 BLE 插件的调用扫描时,我的回调方法永远不会被调用。我在连接的手机(三星 9 )上测试了这个,还通过生成 app-debug.apk 并安装在手机上。
这是我的项目的详细信息。我正在将 Capacitor 用于 native 应用程序。
开发工具包:
tab-1.ts
import { Component, NgZone } from '@angular/core';
import { BLE } from '@ionic-native/ble/ngx';
import { AlertController } from '@ionic/angular';
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
text = 'hello';
devices: any[] = [];
constructor(private ble: BLE,
private ngZone: NgZone,
public alertController: AlertController) { }
scan() {
this.text = 'Loading...';
console.log('going to this.scan.....');
this.devices = [];
this.showAlert('starting scan.....');
this.ble.scan([], 60).subscribe(devices1=>{
this.showDeviceList(devices1);
this.text = devices1;
this.showAlert('scan finished success');
},error=> this.showAlert('scan fini with error'),
()=>this.showAlert('scan void finish'));
}
async showDeviceList(devices) {
const alert = await this.alertController.create({
header: 'Alert',
subHeader: 'Subtitle',
message: 'Going to start scan',
buttons: ['OK']
});
await alert.present();
console.log('devices are ', devices);
this.ngZone.run(() => {
this.devices.push(...devices);
this.text = 'finished';
});
}
async showAlert(msg){
const alert = await this.alertController.create({
header: 'Alert',
subHeader: 'Subtitle',
message: msg,
buttons: ['OK']
});
await alert.present();
}
}
{
"name": "COVID-TRACKING",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"@capacitor/android": "^2.0.1",
"@capacitor/core": "2.0.1",
"@ionic-native/ble": "^5.23.0",
"@ionic-native/core": "^5.0.7",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^5.0.0",
"cordova-plugin-ble-central": "^1.2.4",
"core-js": "^2.5.4",
"rxjs": "~6.5.1",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.20",
"@angular/cli": "~8.3.23",
"@angular/compiler": "~8.2.14",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@capacitor/cli": "2.0.1",
"@ionic/angular-toolkit": "^2.1.1",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
},
"description": "An Ionic project"
}
npm install cordova-plugin-ble-central
npm install @ionic-native/ble
ionic cap sync
最佳答案
问题仅在于 android 10。您需要在 android 10 中获得背景位置权限才能使蓝牙工作。您需要为 AndroidManifest.xml 添加后台位置权限,并且即使您不打算使用它,您也需要将后台地理定位插件添加到您的应用程序中。在你的 app.component 中做这样的事情
const config: BackgroundGeolocationConfig = {
desiredAccuracy: 10,
stationaryRadius: 20,
distanceFilter: 30,
debug: true, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};
this.bgLoc.stop();
完成上述操作后,这将自动请求后台位置权限,并允许蓝牙在 android 10 上工作。还要确保将粗定位权限添加到您的 androidmanifest.xml
关于android - ionic 电容器 BLE 插件扫描不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61180374/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!