vikeri / react-native-background-job

Schedule background jobs in React Native that run your JavaScript when your app is in the background/killed.
MIT License
747 stars 109 forks source link

What is the supported range of Android version? #201

Open Barryhuan opened 1 year ago

Barryhuan commented 1 year ago

The Android version of my mobile phone is 12, and the background will not output test content. I use the simulator to test different versions. This module only supports android 7, that is, API 24-25. The code is as follows:

package.json

{
  "react": "17.0.1",
  "react-native": "0.64.4",
  "react-native-background-job": "^2.3.1"
}
import { Component } from 'react';
import BackgroundJob from "react-native-background-job";
function getCurrentDate() {
  let date = new Date();
  let year = date.getFullYear();
  let month = date.getMonth() + 1;
  let day = date.getDate();
  let hour = date.getHours();
  let minutes = date.getMinutes();
  let second = date.getSeconds();
  let times = [month, day, hour, minutes, second];
  times.forEach((i, _, arr) => i < 10 && (arr[_] = '0' + i));
  return `${year}-${times[0]}-${times[1]} ${times[2]}:${times[3]}:${times[4]}`;
}

BackgroundJob.register({
  jobKey: 'myJobKey',
  job: () => console.log(`${getCurrentDate()}:Background Job fired!`)
});

class App extends Component {
  componentDidMount() {
    BackgroundJob.schedule({
      jobKey: 'myJobKey',
      exact: true,
      allowWhileIdle: true,
      notificationText :"test",
      notificationTitle :'title'
    })
    .then(() => console.log(`${getCurrentDate()}:Success`))
    .catch(err => console.err(err));
  }
  render() {
    return null;
  }
};

export default App;