From b65a35270eacbced1250f8a0af2a442e99819f4c Mon Sep 17 00:00:00 2001 From: EddyVerbruggen Date: Fri, 27 Sep 2019 18:31:32 +0200 Subject: [PATCH] allow instance with missing or background activity #46 --- src/nfc.android.ts | 4 ++-- src/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nfc.android.ts b/src/nfc.android.ts index bf621af..1ff4bfb 100644 --- a/src/nfc.android.ts +++ b/src/nfc.android.ts @@ -421,8 +421,8 @@ export class Nfc implements NfcApi { // The adapter must be started with the foreground activity. // This allows to start it as soon as possible but only once. const foregroundActivity = application.android.foregroundActivity; - this.nfcAdapter = android.nfc.NfcAdapter.getDefaultAdapter(foregroundActivity); - if (!this.started && this.nfcAdapter !== null && foregroundActivity !== null) { + this.nfcAdapter = android.nfc.NfcAdapter.getDefaultAdapter(application.android.context); + if (!this.started && this.nfcAdapter !== null && foregroundActivity) { this.started = true; this.nfcAdapter.enableForegroundDispatch(foregroundActivity, this.pendingIntent, this.intentFilters, this.techLists); // handle any pending intent diff --git a/src/package.json b/src/package.json index 124c46b..2c0a52d 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-nfc", - "version": "4.0.3", + "version": "4.0.4", "description": "NFC plugin for your NativeScript app", "main": "nfc", "typings": "index.d.ts",