0.0.6 • Published 3 years ago

@unicorns-and-unicorns/capacitor-sensors-v2 v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

How to use

Installation

npm install @unicorns-and-unicorns/capacitor-sensors-v2 --save
npx cap sync

In your Ionic Android project, add this code, to make to make Capacitor aware of the plugins

import com.ctss.sensors.Sensors;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      add(Sensors.class);
    }});
  }
}

You can use the Sensors like this

import { Plugins } from '@capacitor/core';
import { SensorData, Sensors } from 'sensors';

useEffect(() => {
	Plugins.Sensors.addListener('magnetometerChange', (res: SensorData) => {
		setMangetometerX(res.x);
		setMangetometerY(res.y);
		setMangetometerZ(res.z);
	});
	Plugins.Sensors.addListener('gyroscopeChange', (res: SensorData) => {
		setGyroscopeX(res.x);
		setGyroscopeY(res.y);
		setGyroscopeZ(res.z);
	});
	Plugins.Sensors.addListener('accelerometerChange', (res: SensorData) => {
		setAccelerometerX(res.x);
		setAccelerometerY(res.y);
		setAccelerometerZ(res.z);
	});

	return () => {
		Plugins.Sensors.removeAllListeners();
	}
}, []);
0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago