Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android_alarm_manager): Add Kotlin dependency and convert AlarmBroadcastReceiver class to Kotlin #2271

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}
}