如何在React Native Android中打开自动亮度?

ac1kyiln  于 2022-12-16  发布在  Android
关注(0)|答案(1)|浏览(138)

我想在我的react原生android应用程序中启用自动亮度。
例如,用户能够在点击按钮时启用自动亮度。
我该怎么做呢?

xu3bshqb

xu3bshqb1#

您可以使用此软件包expo-brightness www.example.com实现此https://docs.expo.dev/versions/latest/sdk/brightness/#brightnesssetsystembrightnessmodeasyncbrightnessmode

import React, { useEffect } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import * as Brightness from 'expo-brightness';

export default function App() {
  useEffect(() => {
    (async () => {
      const { status } = await Brightness.requestPermissionsAsync();
      if (status === 'granted') {
        // ANDROID ONLY
        Brightness.setSystemBrightnessModeAsync(BrightnessMode.AUTOMATIC)
      }
    })();
  }, []);

  return (
    <View style={styles.container}>
      <Text>Brightness Module Example</Text>
    </View>
  );
}

如果您在世博会项目之外使用,请遵循以下说明:https://github.com/expo/expo/tree/sdk-47/packages/expo-brightness

相关问题