react-native-nfc-manager 4.0.0-beta.6 → 4.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ Made with ❤️ by [whitedogg13](https://github.com/whitedogg13) and [revteltec
|
|
|
14
14
|
|
|
15
15
|
## Version Notes
|
|
16
16
|
|
|
17
|
-
- `v3` only supports legacy architecture (
|
|
18
|
-
- `v4` supports new architecture (still in beta,
|
|
17
|
+
- `v3` only supports legacy architecture (`v3.x.y`).
|
|
18
|
+
- `v4` supports new architecture (still in beta, `v4.0.0-beta.x`) .
|
|
19
19
|
|
|
20
20
|
## Table of Contents
|
|
21
21
|
|
|
@@ -45,7 +45,6 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
45
45
|
private static final String LOG_TAG = "ReactNativeNfcManager";
|
|
46
46
|
private final List<IntentFilter> intentFilters = new ArrayList<>();
|
|
47
47
|
private final ArrayList<String[]> techLists = new ArrayList<>();
|
|
48
|
-
private final ReactApplicationContext context;
|
|
49
48
|
private Boolean isForegroundEnabled = false;
|
|
50
49
|
private Boolean isResumed = false;
|
|
51
50
|
private WriteNdefRequest writeNdefRequest = null;
|
|
@@ -82,7 +81,6 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
82
81
|
|
|
83
82
|
public NfcManager(ReactApplicationContext reactContext) {
|
|
84
83
|
super(reactContext);
|
|
85
|
-
context = reactContext;
|
|
86
84
|
reactContext.addActivityEventListener(this);
|
|
87
85
|
reactContext.addLifecycleEventListener(this);
|
|
88
86
|
Log.d(LOG_TAG, "NfcManager created");
|
|
@@ -1055,6 +1053,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1055
1053
|
|
|
1056
1054
|
@ReactMethod
|
|
1057
1055
|
public void start(Callback callback) {
|
|
1056
|
+
var context = getReactApplicationContext();
|
|
1058
1057
|
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
|
1059
1058
|
if (nfcAdapter != null) {
|
|
1060
1059
|
Log.d(LOG_TAG, "start");
|
|
@@ -1080,7 +1079,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1080
1079
|
@ReactMethod
|
|
1081
1080
|
public void isSupported(String tech, Callback callback){
|
|
1082
1081
|
Log.d(LOG_TAG, "isSupported");
|
|
1083
|
-
Activity currentActivity =
|
|
1082
|
+
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
|
|
1084
1083
|
if (currentActivity == null) {
|
|
1085
1084
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1086
1085
|
return;
|
|
@@ -1107,7 +1106,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1107
1106
|
@ReactMethod
|
|
1108
1107
|
public void isEnabled(Callback callback) {
|
|
1109
1108
|
Log.d(LOG_TAG, "isEnabled");
|
|
1110
|
-
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(
|
|
1109
|
+
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getReactApplicationContext());
|
|
1111
1110
|
if (nfcAdapter != null) {
|
|
1112
1111
|
callback.invoke(null, nfcAdapter.isEnabled());
|
|
1113
1112
|
} else {
|
|
@@ -1118,7 +1117,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1118
1117
|
@ReactMethod
|
|
1119
1118
|
public void goToNfcSetting(Callback callback) {
|
|
1120
1119
|
Log.d(LOG_TAG, "goToNfcSetting");
|
|
1121
|
-
Activity currentActivity =
|
|
1120
|
+
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
|
|
1122
1121
|
if (currentActivity == null) {
|
|
1123
1122
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1124
1123
|
return;
|
|
@@ -1134,7 +1133,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1134
1133
|
|
|
1135
1134
|
@ReactMethod
|
|
1136
1135
|
public void getLaunchTagEvent(Callback callback) {
|
|
1137
|
-
Activity currentActivity =
|
|
1136
|
+
Activity currentActivity = getReactApplicationContext().getCurrentActivity();
|
|
1138
1137
|
if (currentActivity == null) {
|
|
1139
1138
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1140
1139
|
return;
|
|
@@ -1349,6 +1348,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1349
1348
|
|
|
1350
1349
|
private void enableDisableForegroundDispatch(boolean enable) {
|
|
1351
1350
|
Log.i(LOG_TAG, "enableForegroundDispatch, enable = " + enable);
|
|
1351
|
+
var context = getReactApplicationContext();
|
|
1352
1352
|
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
|
1353
1353
|
Activity currentActivity = context.getCurrentActivity();
|
|
1354
1354
|
final NfcManager manager = this;
|
|
@@ -1407,7 +1407,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1407
1407
|
}
|
|
1408
1408
|
|
|
1409
1409
|
private PendingIntent getPendingIntent() {
|
|
1410
|
-
Activity activity =
|
|
1410
|
+
Activity activity = getReactApplicationContext().getCurrentActivity();
|
|
1411
1411
|
assert activity != null;
|
|
1412
1412
|
Intent intent = new Intent(activity, activity.getClass());
|
|
1413
1413
|
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
@@ -1440,7 +1440,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1440
1440
|
Log.d(LOG_TAG, "onReceive " + intent);
|
|
1441
1441
|
final String action = intent.getAction();
|
|
1442
1442
|
|
|
1443
|
-
if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
|
|
1443
|
+
if (action != null && action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
|
|
1444
1444
|
final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE,
|
|
1445
1445
|
NfcAdapter.STATE_OFF);
|
|
1446
1446
|
String stateStr = "unknown";
|