Skip to content

Commit

Permalink
fix(android_alarm_manager): Add Kotlin dependency and convert AlarmBr…
Browse files Browse the repository at this point in the history
…oadcastReceiver class to Kotlin
  • Loading branch information
TheFinestArtist authored and vbuberen committed Nov 29, 2023
1 parent eeab903 commit 0052d3f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
8 changes: 8 additions & 0 deletions packages/android_alarm_manager_plus/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ group 'dev.fluttercommunity.plus.androidalarmmanager'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.7.22'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:8.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand All @@ -20,6 +22,7 @@ rootProject.allprojects {
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 33
Expand All @@ -31,6 +34,10 @@ android {
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

defaultConfig {
minSdkVersion 19
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -42,6 +49,7 @@ android {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.6.1'
api 'androidx.core:core:1.10.1'
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package dev.fluttercommunity.plus.androidalarmmanager

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent

class AlarmBroadcastReceiver : BroadcastReceiver() {
/**
* Invoked by the OS when a timer goes off.
*
* The associated timer was registered in [AlarmService].
*
* In Android, timer notifications require a [BroadcastReceiver] as the artifact that is
* notified when the timer goes off. As a result, this method is kept simple, immediately
* offloading any work to [AlarmService.enqueueAlarmProcessing].
*
* This method is the beginning of an execution path that will eventually execute a desired
* Dart callback function, as registered by the Dart side of the android_alarm_manager plugin.
* However, there may be asynchronous gaps between [onReceive] and the eventual invocation
* of the Dart callback because [AlarmService] may need to spin up a Flutter execution
* context before the callback can be invoked.
*/
override fun onReceive(context: Context, intent: Intent) {
AlarmService.enqueueAlarmProcessing(context, intent)
}
}

0 comments on commit 0052d3f

Please sign in to comment.