Permalink
Browse files

Merge pull request #11 from ajwhite/android-updates

Android updates catching up to iOS
  • Loading branch information...
ajwhite committed Jan 3, 2018
2 parents 9c53a1b + d009ade commit d5dda7474b2a49ec8f7d7b15e231ae4374dfd1ca
Showing with 19 additions and 3 deletions.
  1. +19 −3 android/src/main/java/com/robinpowered/react/battery/DeviceBatteryModule.java
@@ -5,6 +5,7 @@
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import android.os.BatteryManager;
import android.util.Log;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
@@ -13,9 +14,13 @@
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.Promise;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.core.RCTNativeAppEventEmitter;
import com.facebook.react.bridge.LifecycleEventListener;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
// @link http://developer.android.com/training/monitoring-device-state/battery-monitoring.html
@@ -62,12 +67,23 @@ public void notifyBatteryStateChanged(Intent intent) {
// only emit an event if the Catalyst instance is avialable
if (getReactApplicationContext().hasActiveCatalystInstance()) {
WritableNativeMap params = getJSMap(intent);
getReactApplicationContext()
.getJSModule(RCTNativeAppEventEmitter.class)
.emit(EVENT_NAME, params);
try {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(EVENT_NAME, params);
} catch (Exception e) {
Log.e(getName(), "notifyBatteryStateChanged called before bundle loaded");
}
}
}
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
constants.put("BATTERY_CHANGE_EVENT", EVENT_NAME);
return constants;
}
@ReactMethod
public void getBatteryLevel(Promise promise) {
if (batteryStatus != null) {

0 comments on commit d5dda74

Please sign in to comment.