capacitor-enable-gps-plugin 0.1.1 → 0.1.2

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.
@@ -5,6 +5,8 @@ import android.content.Context;
5
5
  import android.content.Intent;
6
6
  import android.content.IntentSender;
7
7
  import android.location.LocationManager;
8
+ import android.os.Handler;
9
+ import android.os.Looper;
8
10
  import android.provider.Settings;
9
11
 
10
12
  import androidx.activity.result.ActivityResult;
@@ -25,6 +27,7 @@ import com.google.android.gms.location.Priority;
25
27
  public class EnableGpsPlugin extends Plugin {
26
28
  private static final int REQUEST_ENABLE_GPS = 7241;
27
29
 
30
+ private final Handler mainHandler = new Handler(Looper.getMainLooper());
28
31
  private PluginCall pendingEnableGpsCall;
29
32
 
30
33
  @PluginMethod
@@ -69,9 +72,11 @@ public class EnableGpsPlugin extends Plugin {
69
72
  .addOnFailureListener(error -> {
70
73
  if (error instanceof ResolvableApiException) {
71
74
  try {
75
+ call.setKeepAlive(true);
72
76
  pendingEnableGpsCall = call;
73
77
  ((ResolvableApiException) error).startResolutionForResult(activity, REQUEST_ENABLE_GPS);
74
78
  } catch (IntentSender.SendIntentException sendError) {
79
+ call.setKeepAlive(false);
75
80
  pendingEnableGpsCall = null;
76
81
  openLocationSettings(call);
77
82
  }
@@ -90,10 +95,18 @@ public class EnableGpsPlugin extends Plugin {
90
95
  }
91
96
 
92
97
  PluginCall call = pendingEnableGpsCall;
93
- pendingEnableGpsCall = null;
94
98
 
95
99
  if (call != null) {
96
- resolveEnabled(call);
100
+ completePendingEnableGpsCall();
101
+ }
102
+ }
103
+
104
+ @Override
105
+ protected void handleOnResume() {
106
+ super.handleOnResume();
107
+
108
+ if (pendingEnableGpsCall != null) {
109
+ mainHandler.postDelayed(this::completePendingEnableGpsCall, 500);
97
110
  }
98
111
  }
99
112
 
@@ -117,6 +130,18 @@ public class EnableGpsPlugin extends Plugin {
117
130
  call.resolve(result);
118
131
  }
119
132
 
133
+ private void completePendingEnableGpsCall() {
134
+ PluginCall call = pendingEnableGpsCall;
135
+ pendingEnableGpsCall = null;
136
+
137
+ if (call == null) {
138
+ return;
139
+ }
140
+
141
+ call.setKeepAlive(false);
142
+ resolveEnabled(call);
143
+ }
144
+
120
145
  private boolean isLocationEnabled() {
121
146
  LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
122
147
  if (locationManager == null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-enable-gps-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Capacitor plugin for requesting users to enable Android GPS/location services.",
5
5
  "type": "module",
6
6
  "main": "dist/esm/index.js",