Skip to content

Commit 6885ee5

Browse files
committed
chore(android): fix deprecations
1 parent 0254723 commit 6885ee5

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

src/ble/index.android.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/* eslint-disable no-caller */
2-
import { AndroidActivityRequestPermissionsEventData, AndroidActivityResultEventData, AndroidApplication, android as andApp } from '@nativescript/core/application';
2+
import { arrayToNativeArray } from '@nativescript-community/arraybuffers';
3+
import { Application, Device, Trace, Utils } from '@nativescript/core';
4+
import { AndroidActivityResultEventData, AndroidApplication } from '@nativescript/core/application';
5+
import PQueue from 'p-queue';
36
import {
47
AdvertismentData,
58
BleTraceCategory,
@@ -27,9 +30,6 @@ import {
2730
bluetoothEnabled,
2831
prepareArgs
2932
} from './index.common';
30-
import PQueue from 'p-queue';
31-
import { Application, Device, Trace, Utils } from '@nativescript/core';
32-
import { arrayToNativeArray } from '@nativescript-community/arraybuffers';
3333
let _bluetoothInstance: Bluetooth;
3434
export function getBluetoothInstance() {
3535
if (!_bluetoothInstance) {
@@ -1165,7 +1165,7 @@ export class Bluetooth extends BluetoothCommon {
11651165
if (Trace.isEnabled()) {
11661166
CLog(CLogTypes.info, 'Android Bluetooth registering for state change');
11671167
}
1168-
andApp.registerBroadcastReceiver(android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED, (context: android.content.Context, intent: android.content.Intent) => {
1168+
Application.android.registerBroadcastReceiver(android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED, (context: android.content.Context, intent: android.content.Intent) => {
11691169
const state = intent.getIntExtra(android.bluetooth.BluetoothAdapter.EXTRA_STATE, android.bluetooth.BluetoothAdapter.ERROR);
11701170
if (Trace.isEnabled()) {
11711171
CLog(CLogTypes.info, 'Android Bluetooth ACTION_STATE_CHANGED', state, android.bluetooth.BluetoothAdapter.STATE_ON, android.bluetooth.BluetoothAdapter.STATE_OFF);
@@ -1191,7 +1191,7 @@ export class Bluetooth extends BluetoothCommon {
11911191
return;
11921192
}
11931193
this.broadcastRegistered = false;
1194-
andApp.unregisterBroadcastReceiver(android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED);
1194+
Application.android.unregisterBroadcastReceiver(android.bluetooth.BluetoothAdapter.ACTION_STATE_CHANGED);
11951195
}
11961196
onListenerAdded(eventName: string, count: number) {
11971197
if (Trace.isEnabled()) {
@@ -1233,10 +1233,10 @@ export class Bluetooth extends BluetoothCommon {
12331233
CLog(CLogTypes.info, 'Bluetooth.enableGPS');
12341234
}
12351235
return new Promise((resolve, reject) => {
1236-
const activity = andApp.foregroundActivity || andApp.startActivity;
1236+
const activity = Application.android.foregroundActivity || Application.android.startActivity;
12371237
if (!this.isGPSEnabled()) {
12381238
const onActivityResultHandler = (data: AndroidActivityResultEventData) => {
1239-
andApp.off(AndroidApplication.activityResultEvent, onActivityResultHandler);
1239+
Application.android.off(AndroidApplication.activityResultEvent, onActivityResultHandler);
12401240
if (data.requestCode === 0) {
12411241
if (this.isGPSEnabled()) {
12421242
resolve();
@@ -1245,7 +1245,7 @@ export class Bluetooth extends BluetoothCommon {
12451245
}
12461246
}
12471247
};
1248-
andApp.on(AndroidApplication.activityResultEvent, onActivityResultHandler);
1248+
Application.android.on(AndroidApplication.activityResultEvent, onActivityResultHandler);
12491249
activity.startActivityForResult(new android.content.Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
12501250
} else {
12511251
resolve();
@@ -1275,7 +1275,7 @@ export class Bluetooth extends BluetoothCommon {
12751275
if (args.requestCode === ACTION_REQUEST_ENABLE_BLUETOOTH_REQUEST_CODE) {
12761276
try {
12771277
// remove the event listener
1278-
andApp.off(AndroidApplication.activityResultEvent, onBluetoothEnableResult);
1278+
Application.android.off(AndroidApplication.activityResultEvent, onBluetoothEnableResult);
12791279

12801280
// RESULT_OK = -1
12811281
if (args.resultCode === android.app.Activity.RESULT_OK) {
@@ -1287,23 +1287,23 @@ export class Bluetooth extends BluetoothCommon {
12871287
if (Trace.isEnabled()) {
12881288
CLog(CLogTypes.error, ex);
12891289
}
1290-
andApp.off(AndroidApplication.activityResultEvent, onBluetoothEnableResult);
1290+
Application.android.off(AndroidApplication.activityResultEvent, onBluetoothEnableResult);
12911291
reject(ex);
12921292
return;
12931293
}
12941294
} else {
1295-
andApp.off(AndroidApplication.activityResultEvent, onBluetoothEnableResult);
1295+
Application.android.off(AndroidApplication.activityResultEvent, onBluetoothEnableResult);
12961296
resolve(false);
12971297
return;
12981298
}
12991299
};
13001300

13011301
// set the onBluetoothEnableResult for the intent
1302-
andApp.on(AndroidApplication.activityResultEvent, onBluetoothEnableResult);
1302+
Application.android.on(AndroidApplication.activityResultEvent, onBluetoothEnableResult);
13031303

13041304
// create the intent to start the bluetooth enable request
13051305
const intent = new android.content.Intent(android.bluetooth.BluetoothAdapter.ACTION_REQUEST_ENABLE);
1306-
const activity = andApp.foregroundActivity || andApp.startActivity;
1306+
const activity = Application.android.foregroundActivity || Application.android.startActivity;
13071307
if (Trace.isEnabled()) {
13081308
CLog(CLogTypes.info, methodName, 'startActivityForResult');
13091309
}
@@ -1358,11 +1358,11 @@ export class Bluetooth extends BluetoothCommon {
13581358
public openBluetoothSettings() {
13591359
const methodName = 'openBluetoothSettings';
13601360
return new Promise<void>((resolve, reject) => {
1361-
const activity = andApp.foregroundActivity || andApp.startActivity;
1361+
const activity = Application.android.foregroundActivity || Application.android.startActivity;
13621362
if (!this._isEnabled()) {
13631363
const that = this;
13641364
const onActivityResultHandler = function (data: AndroidActivityResultEventData) {
1365-
andApp.off(AndroidApplication.activityResultEvent, onActivityResultHandler);
1365+
Application.android.off(Application.android.activityResultEvent, onActivityResultHandler);
13661366
if (data.requestCode === 0) {
13671367
if (that._isEnabled()) {
13681368
resolve();
@@ -1371,7 +1371,7 @@ export class Bluetooth extends BluetoothCommon {
13711371
}
13721372
}
13731373
};
1374-
andApp.on(AndroidApplication.activityResultEvent, onActivityResultHandler);
1374+
Application.android.on(Application.android.activityResultEvent, onActivityResultHandler);
13751375
activity.startActivityForResult(new android.content.Intent(android.provider.Settings.ACTION_BLUETOOTH_SETTINGS), 0);
13761376
} else {
13771377
resolve();

0 commit comments

Comments
 (0)