react-native-autostarter
v1.0.5
Published
A wrapper of AutoStarter android library
Downloads
16
Readme
react-native-autostarter
This is a wrapper of Autostarter
Getting started
$ npm install react-native-autostarter --save
or
$ yarn add react-native-autostarter
Mostly automatic installation
$ react-native link react-native-autostarter
Usage
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>
);
};
Running the example
cd example
yarn
react-native run-android
License
react-native-autostarter
is MIT licensed, as found in the LICENSE file.