Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/battery_plus/battery_plus/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:1.10.1"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.fluttercommunity.plus.battery

import android.annotation.SuppressLint
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
import io.flutter.plugin.common.EventChannel
import io.flutter.embedding.engine.plugins.FlutterPlugin
Expand All @@ -20,6 +21,9 @@ import java.util.Locale
import android.os.PowerManager
import android.provider.Settings
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED


/** BatteryPlusPlugin */
class BatteryPlusPlugin : MethodCallHandler, EventChannel.StreamHandler, FlutterPlugin {
Expand Down Expand Up @@ -77,9 +81,16 @@ class BatteryPlusPlugin : MethodCallHandler, EventChannel.StreamHandler, Flutter
}
}

@SuppressLint("WrongConstant") // Error in ContextCompat for RECEIVER_NOT_EXPORTED
Copy link
Contributor Author

@reidbaker reidbaker May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed a bug against androidx for this behavior https://b.corp.google.com/issues/282596027

override fun onListen(arguments: Any?, events: EventSink) {
chargingStateChangeReceiver = createChargingStateChangeReceiver(events)
applicationContext?.registerReceiver(chargingStateChangeReceiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
// DO NOT MERGE, this alternates states. reidbaker debug before review.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a forgotten comment? Because I see that the PR is marked as ready for review, but this comment is here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry I wanted to make sure not to merge/reivew until my local testing worked. Sorry, removed.

applicationContext?.let {
ContextCompat.registerReceiver(
it, chargingStateChangeReceiver,
IntentFilter(Intent.ACTION_BATTERY_CHANGED), RECEIVER_NOT_EXPORTED
)
}
val status = getBatteryStatus()
publishBatteryStatus(events, status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}