Curriculum
Course: Introduction to Expo
Login

Curriculum

Introduction to Expo

Text lesson

Lesson 5: Managing Device Sensors and Notifications

Managing Device Sensors and Notifications

  1. Using Device Sensors:

    • Accelerometer:

      import { Accelerometer } from 'expo-sensors';
      const [data, setData] = useState({});
      useEffect(() => {
      const subscription = Accelerometer.addListener(accelerometerData => {
      setData(accelerometerData);
      });
      return () => subscription.remove();
      }, []);
    • Gyroscope:

      import { Gyroscope } from 'expo-sensors';
      const [data, setData] = useState({});
      useEffect(() => {
      const subscription = Gyroscope.addListener(gyroscopeData => {
      setData(gyroscopeData);
      });
      return () => subscription.remove();
      }, []);
  2. Sending Notifications:

    import * as Notifications from 'expo-notifications';

    Notifications.scheduleNotificationAsync({
    content: {
    title: "Time to study!",
    body: "Don't forget to complete your React Native lesson.",
    },
    trigger: { seconds: 5 },
    });

 

Conclusion: Accessing device sensors and sending notifications can greatly enhance the functionality and user engagement of your app. Expo provides easy-to-use APIs for these tasks, making it simple to implement these features.

Layer 1
Login Categories
This website uses cookies and asks your personal data to enhance your browsing experience.