diff --git a/SystemSetting.js b/SystemSetting.js index d6cdd11..5d5ce21 100644 --- a/SystemSetting.js +++ b/SystemSetting.js @@ -141,9 +141,12 @@ export default class SystemSetting { return (result) > 0 } - static switchWifiSilence(complete) { + static async switchWifiSilence(complete) { if (Utils.isAndroid) { - SystemSetting.listenEvent(complete) + let listener = await SystemSetting.addWifiListener(() => { + SystemSetting.removeListener(listener); + complete(); + }); SystemSettingNative.switchWifiSilence() } else { SystemSetting.switchWifi(complete) @@ -181,9 +184,12 @@ export default class SystemSetting { SystemSettingNative.switchBluetooth() } - static switchBluetoothSilence(complete) { + static async switchBluetoothSilence(complete) { if (Utils.isAndroid) { - SystemSetting.listenEvent(complete) + let listener = await SystemSetting.addBluetoothListener(() => { + SystemSetting.removeListener(listener); + complete(); + }) SystemSettingNative.switchBluetoothSilence() } else { SystemSettingNative.switchBluetooth(complete) @@ -268,4 +274,4 @@ export default class SystemSetting { complete() }) } -} \ No newline at end of file +} diff --git a/android/src/main/java/com/ninty/system/setting/SystemSetting.java b/android/src/main/java/com/ninty/system/setting/SystemSetting.java index dedd524..b119117 100644 --- a/android/src/main/java/com/ninty/system/setting/SystemSetting.java +++ b/android/src/main/java/com/ninty/system/setting/SystemSetting.java @@ -246,6 +246,7 @@ public void run() { public void getAppBrightness(Promise promise) { final Activity curActivity = getCurrentActivity(); if (curActivity == null) { + promise.reject("-1", "cannot get app brightness: current activity is null"); return; } try { @@ -597,4 +598,14 @@ public void onReceive(Context context, Intent intent) { } } } + + @ReactMethod + public void addListener(String eventName) { + // Keep: Required for RN built in Event Emitter Calls. + } + + @ReactMethod + public void removeListeners(Integer count) { + // Keep: Required for RN built in Event Emitter Calls. + } } diff --git a/ios/RTCSystemSetting.m b/ios/RTCSystemSetting.m index 3f2e874..525922a 100644 --- a/ios/RTCSystemSetting.m +++ b/ios/RTCSystemSetting.m @@ -165,6 +165,14 @@ +(BOOL)requiresMainQueueSetup{ } } +RCT_EXPORT_METHOD(addListener : (NSString *)eventName) { + // Keep: Required for RN built in Event Emitter Calls. +} + +RCT_EXPORT_METHOD(removeListeners : (NSInteger)count) { + // Keep: Required for RN built in Event Emitter Calls. +} + -(void)showVolumeUI:(BOOL)flag{ if(flag && [volumeView superview]){ [volumeView removeFromSuperview]; diff --git a/package.json b/package.json index 80bb4b1..1f33b91 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-system-setting", - "version": "1.7.6", + "version": "1.7.7", "description": "provide some system setting APIs. Volume, brightness, wifi, location, bluetooth, airplane...", "main": "SystemSetting.js", "types": "SystemSetting.d.ts",