@unicorns-and-unicorns/capacitor-sensors-v2
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

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();
	}
}, []);

Readme

Keywords

Package Sidebar

Install

npm i @unicorns-and-unicorns/capacitor-sensors-v2

Weekly Downloads

5

Version

0.0.6

License

MIT

Unpacked Size

113 kB

Total Files

41

Last publish

Collaborators

  • githubctss
  • uu-development