| | |
| | | import android.content.IntentFilter; |
| | | import android.os.BatteryManager; |
| | | |
| | | import com.secondworld.sdk.GameApp; |
| | | import com.secondworld.sdk.GameAppProxy; |
| | | import com.secondworld.sdk.UnityMsgHandler; |
| | | |
| | | import java.util.HashMap; |
| | |
| | | public void start() { |
| | | m_BatteryBroadCastReceiver = new BatteryBroadCastReceiver(); |
| | | IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED); |
| | | GameApp.I.registerReceiver(m_BatteryBroadCastReceiver, filter); |
| | | GameAppProxy.app.registerReceiver(m_BatteryBroadCastReceiver, filter); |
| | | } |
| | | |
| | | public void stop() { |
| | | if (m_BatteryBroadCastReceiver != null) { |
| | | try { |
| | | GameApp.I.unregisterReceiver(m_BatteryBroadCastReceiver); |
| | | GameAppProxy.app.unregisterReceiver(m_BatteryBroadCastReceiver); |
| | | m_BatteryBroadCastReceiver = null; |
| | | } catch (IllegalArgumentException e) { |
| | | if (!Objects.requireNonNull(e.getMessage()).contains("Receiver not registered")) { |
| | |
| | | |
| | | if (_batteryLevel != m_BatteryLevel) { |
| | | try { |
| | | _msg.put("code", CodeA2U.BatteryLevel); |
| | | _msg.put("level", _batteryLevel); |
| | | |
| | | UnityMsgHandler.sendMessageToUnity(_msg); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.BatteryLevel,_msg); |
| | | |
| | | m_BatteryLevel = _batteryLevel; |
| | | |
| | |
| | | _transCode = 3; |
| | | } |
| | | |
| | | _msg.put("code", CodeA2U.BatteryCharging); |
| | | _msg.put("status", _transCode); |
| | | |
| | | UnityMsgHandler.sendMessageToUnity(_msg); |
| | | UnityMsgHandler.sendMessageToUnity(CodeA2U.BatteryCharging,_msg); |
| | | |
| | | m_Status = _status; |
| | | } |