Git Product home page Git Product logo

timekeeper's Introduction

TimeKeeper

Alarms scheduling for Android.

Set and receive exact alarms with ease, TimeKeeper handle all the work for you.

Support Android 8.0 (API level 26) back to Android 4.0 (API level 14)

In order to support exact alarms on Android 9.0 your app has to be in the foreground at any time, this can be achieved by using a foreground service running at all time. Otherwise your app will be subject to App Standby Buckets and alarms may be deferred by few minutes or more according to Power management restrictions

Instructions

Add dependencies to your app build.gradle (This library uses Firebase Job Dispatcher)

dependencies {
    // TimeKeeper
    implementation 'com.tomergoldst.android:timekeeper:1.0.2'

    // Firebase Job Dispatcher
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
}

Add the following permissions to your app manifest if you don't already have it

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

Create a BroadcastReceiver (Alarms will be delivered to this receiver)

public class MyAlarmReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        /*
          Extract alarms from intent
         */
        List<Alarm> alarms = intent.getParcelableArrayListExtra("alarms");

    }
}

Add receiver to your manifest. It is important to define the intent-filter with the appropriate action name

<receiver
    android:name=".MyAlarmReceiver"
    android:exported="false">
    <intent-filter>
        <action android:name="com.tomergoldst.timekeeper.intent_action.RECEIVE_ALARMS" />
    </intent-filter>
</receiver>

Init TimeKeeper at your application class onCreate()

public class MyApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        TimeKeeper.initialize(this);
    }
}

Now we can start using the sdk and create an alarm: Create an Alarm object and pass in a UID and a time to be triggered in millis and then call setAlarm

Alarm alarm = new Alarm("my-alarm-id", 1541433600000);
TimeKeeper.setAlarm(alarm);

To cancel an alarm:

TimeKeeper.cancelAlarm("my-alarm-id");

To see list of all existing alarms:

List<Alarm> alarms = TimeKeeper.getAlarms();

To remove all alarms:

TimeKeeper.clear();

To get next alarm time:

long time = TimeKeeper.getNextAlarmTime();

License

Copyright 2018 Tomer Goldstein

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

timekeeper's People

Contributors

tomergoldst avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.