capacitor-enable-gps-plugin 0.1.0 → 0.1.1

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.
@@ -23,6 +23,9 @@ import com.google.android.gms.location.Priority;
23
23
 
24
24
  @CapacitorPlugin(name = "EnableGps")
25
25
  public class EnableGpsPlugin extends Plugin {
26
+ private static final int REQUEST_ENABLE_GPS = 7241;
27
+
28
+ private PluginCall pendingEnableGpsCall;
26
29
 
27
30
  @PluginMethod
28
31
  public void isEnabled(PluginCall call) {
@@ -66,9 +69,10 @@ public class EnableGpsPlugin extends Plugin {
66
69
  .addOnFailureListener(error -> {
67
70
  if (error instanceof ResolvableApiException) {
68
71
  try {
69
- IntentSender intentSender = ((ResolvableApiException) error).getResolution().getIntentSender();
70
- startIntentSenderForResult(call, intentSender, "enableGpsResult");
72
+ pendingEnableGpsCall = call;
73
+ ((ResolvableApiException) error).startResolutionForResult(activity, REQUEST_ENABLE_GPS);
71
74
  } catch (IntentSender.SendIntentException sendError) {
75
+ pendingEnableGpsCall = null;
72
76
  openLocationSettings(call);
73
77
  }
74
78
  } else {
@@ -77,13 +81,20 @@ public class EnableGpsPlugin extends Plugin {
77
81
  });
78
82
  }
79
83
 
80
- @ActivityCallback
81
- private void enableGpsResult(PluginCall call, ActivityResult result) {
82
- if (call == null) {
84
+ @Override
85
+ protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
86
+ super.handleOnActivityResult(requestCode, resultCode, data);
87
+
88
+ if (requestCode != REQUEST_ENABLE_GPS) {
83
89
  return;
84
90
  }
85
91
 
86
- resolveEnabled(call);
92
+ PluginCall call = pendingEnableGpsCall;
93
+ pendingEnableGpsCall = null;
94
+
95
+ if (call != null) {
96
+ resolveEnabled(call);
97
+ }
87
98
  }
88
99
 
89
100
  @ActivityCallback
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-enable-gps-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
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",