capacitor-enable-gps-plugin 0.1.0 → 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;
|
|
@@ -23,6 +25,10 @@ import com.google.android.gms.location.Priority;
|
|
|
23
25
|
|
|
24
26
|
@CapacitorPlugin(name = "EnableGps")
|
|
25
27
|
public class EnableGpsPlugin extends Plugin {
|
|
28
|
+
private static final int REQUEST_ENABLE_GPS = 7241;
|
|
29
|
+
|
|
30
|
+
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
31
|
+
private PluginCall pendingEnableGpsCall;
|
|
26
32
|
|
|
27
33
|
@PluginMethod
|
|
28
34
|
public void isEnabled(PluginCall call) {
|
|
@@ -66,9 +72,12 @@ public class EnableGpsPlugin extends Plugin {
|
|
|
66
72
|
.addOnFailureListener(error -> {
|
|
67
73
|
if (error instanceof ResolvableApiException) {
|
|
68
74
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
75
|
+
call.setKeepAlive(true);
|
|
76
|
+
pendingEnableGpsCall = call;
|
|
77
|
+
((ResolvableApiException) error).startResolutionForResult(activity, REQUEST_ENABLE_GPS);
|
|
71
78
|
} catch (IntentSender.SendIntentException sendError) {
|
|
79
|
+
call.setKeepAlive(false);
|
|
80
|
+
pendingEnableGpsCall = null;
|
|
72
81
|
openLocationSettings(call);
|
|
73
82
|
}
|
|
74
83
|
} else {
|
|
@@ -77,13 +86,28 @@ public class EnableGpsPlugin extends Plugin {
|
|
|
77
86
|
});
|
|
78
87
|
}
|
|
79
88
|
|
|
80
|
-
@
|
|
81
|
-
|
|
82
|
-
|
|
89
|
+
@Override
|
|
90
|
+
protected void handleOnActivityResult(int requestCode, int resultCode, Intent data) {
|
|
91
|
+
super.handleOnActivityResult(requestCode, resultCode, data);
|
|
92
|
+
|
|
93
|
+
if (requestCode != REQUEST_ENABLE_GPS) {
|
|
83
94
|
return;
|
|
84
95
|
}
|
|
85
96
|
|
|
86
|
-
|
|
97
|
+
PluginCall call = pendingEnableGpsCall;
|
|
98
|
+
|
|
99
|
+
if (call != null) {
|
|
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);
|
|
110
|
+
}
|
|
87
111
|
}
|
|
88
112
|
|
|
89
113
|
@ActivityCallback
|
|
@@ -106,6 +130,18 @@ public class EnableGpsPlugin extends Plugin {
|
|
|
106
130
|
call.resolve(result);
|
|
107
131
|
}
|
|
108
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
|
+
|
|
109
145
|
private boolean isLocationEnabled() {
|
|
110
146
|
LocationManager locationManager = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
|
|
111
147
|
if (locationManager == null) {
|