This is a wrapper of Autostarter
$ npm install react-native-autostarter --save
or
$ yarn add react-native-autostarter
$ react-native link react-native-autostarter
Basic usage
import Autostarter from "react-native-autostarter";
// check if the device model is available on the autostart permissions
Autostarter.isAutoStartPermissionAvailable().then(isAvailable => {
Autostarter.getAutoStartPermission();
});
Or, you can display a fallback screen or overlay if auto-start permission is not available.
import React, { useCallback, useEffect, useState } from "react";
import { Button, FlatList, Text, View } from "react-native";
import Autostarter from "react-native-autostarter";
const AutoStarterOverlay = () => {
const onPress = useCallback(() => {
Autostarter.getAutoStartPermission();
}, []);
return (
<View>
<Text>
To receive push notification, please remove it from battery optimization
</Text>
<Button onPress={onPress}>Enable</Button>
</View>
);
};
const MyApp = () => {
const [autoStartPermission, setAutoStartPermission] = useState(false);
useEffect(() => {
Autostarter.isAutoStartPermissionAvailable().then(isAvailable => {
setAutoStartPermission(isAvailable);
});
}, []);
return (
<View>
{autoStartPermission ? <AutoStarterOverlay /> : null}
<Text>Lorem Ipsum</Text>
</View>
);
};
cd example
yarn
react-native run-android
react-native-autostarter
is MIT licensed, as found in the LICENSE file.