react-native-android-background-timer

1.0.4 • Public • Published

react-native-android-background-timer

Emit event periodically (even when app is in the background or the phone is locked).

Getting started

$ npm install react-native-android-background-timer --save

Mostly automatic installation

$ react-native link react-native-android-background-timer

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactlibrary.RNAndroidBackgroundTimerPackage; to the imports at the top of the file
  • Add new RNAndroidBackgroundTimerPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-android-background-timer'
    project(':react-native-android-background-timer').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-android-background-timer/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-android-background-timer')
    

Usage

You can use the setInterval and setTimeout functions. This API is identical to that of react-native and can be used to quickly replace existing timers with background timers.

import RNAndroidBackgroundTimer from 'react-native-android-background-timer';
// Start a timer that runs continuous after X milliseconds
const intervalId = RNAndroidBackgroundTimer.setInterval(() => {
// this will be executed every 200 ms
// even when app is the the background
console.log('tic');
}, 200);
// Cancel the timer when you are done with it
RNAndroidBackgroundTimer.clearInterval(intervalId);

Don't forget to add

 �<uses-permission android:name="android.permission.WAKE_LOCK" />

� to your manifest.

Readme

Keywords

Package Sidebar

Install

npm i react-native-android-background-timer

Weekly Downloads

10

Version

1.0.4

License

gpl v3

Last publish

Collaborators

  • alimiracle