@dreiver1/capacitor-step-counter 0.0.1 → 0.0.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.
package/android/src/main/java/com/davidnascimento/plugins/stepcounter/StepCounterPlugin.java
CHANGED
|
@@ -22,7 +22,8 @@ import com.getcapacitor.annotation.Permission;
|
|
|
22
22
|
)
|
|
23
23
|
}
|
|
24
24
|
)
|
|
25
|
-
public class StepCounterPlugin extends Plugin
|
|
25
|
+
public class StepCounterPlugin extends Plugin
|
|
26
|
+
implements SensorEventListener {
|
|
26
27
|
|
|
27
28
|
private SensorManager sensorManager;
|
|
28
29
|
private Sensor stepSensor;
|
|
@@ -30,16 +31,17 @@ public class StepCounterPlugin extends Plugin implements SensorEventListener {
|
|
|
30
31
|
|
|
31
32
|
@Override
|
|
32
33
|
public void load() {
|
|
33
|
-
sensorManager =
|
|
34
|
-
getContext().getSystemService(Context.SENSOR_SERVICE);
|
|
35
|
-
stepSensor =
|
|
34
|
+
sensorManager =
|
|
35
|
+
(SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
|
|
36
|
+
stepSensor =
|
|
37
|
+
sensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
@PluginMethod
|
|
39
41
|
public void start(PluginCall call) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
requestPermissionForAlias("activityRecognition", call
|
|
42
|
+
|
|
43
|
+
if (getPermissionState("activityRecognition") != PermissionState.GRANTED) {
|
|
44
|
+
requestPermissionForAlias("activityRecognition", call);
|
|
43
45
|
return;
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -70,18 +72,12 @@ public class StepCounterPlugin extends Plugin implements SensorEventListener {
|
|
|
70
72
|
call.resolve(ret);
|
|
71
73
|
}
|
|
72
74
|
|
|
73
|
-
@PermissionCallback
|
|
74
|
-
private void permissionCallback(PluginCall call) {
|
|
75
|
-
start(call);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
75
|
@Override
|
|
79
76
|
public void onSensorChanged(SensorEvent event) {
|
|
80
77
|
currentSteps = event.values[0];
|
|
81
78
|
|
|
82
79
|
JSObject data = new JSObject();
|
|
83
80
|
data.put("steps", currentSteps);
|
|
84
|
-
|
|
85
81
|
notifyListeners("step", data);
|
|
86
82
|
}
|
|
87
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dreiver1/capacitor-step-counter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "A Capacitor plugin that provides access to the device step counter sensor on Android and iOS, with a web fallback.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -82,5 +82,8 @@
|
|
|
82
82
|
"android": {
|
|
83
83
|
"src": "android"
|
|
84
84
|
}
|
|
85
|
+
},
|
|
86
|
+
"dependencies": {
|
|
87
|
+
"step-counter": "github:dreiver1/capacitor-step-counter"
|
|
85
88
|
}
|
|
86
|
-
}
|
|
89
|
+
}
|