From: snickersun Date: Mon, 30 Nov 2020 18:12:30 +0000 (+0800) Subject: 解决每次启动,声音无法根据客户设置进行记忆,只能最大音量问题。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=6850b8915214c3dc33314be7605e20dc735c437a;p=protocol_srv.git 解决每次启动,声音无法根据客户设置进行记忆,只能最大音量问题。 --- diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index 4c747486..1fe12bee 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -7,6 +7,7 @@ import android.app.Service; import android.content.IClipboard; import android.content.Intent; import android.media.AudioManager; +import android.media.MediaRouter; import android.os.Handler; import android.os.IBinder; @@ -362,15 +363,15 @@ public class CoreService extends Service { Runtime runtime; private BroadcastReceiver screenOnReceiver = new BroadcastReceiver() { - public void onReceive(Context param1Context, Intent param1Intent) { + public void onReceive(Context context, Intent intent) { - if ("android.intent.action.SCREEN_ON".equals(param1Intent.getAction())) { + if ("android.intent.action.SCREEN_ON".equals(intent.getAction())) { StringBuilder var3 = new StringBuilder(); var3.append("screen on wake is_wifi_network_ok="); var3.append(CoreService.is_wifi_network_ok); ICLogger.i(var3.toString()); //检测电池电量 并上报低电报警 - batteryUtil.getBatteryLevel(param1Context); + batteryUtil.getBatteryLevel(context); if (CoreService.is_in_sleep_mode) { /*屏幕亮起时,如果在sleep模式(夜晚的那个睡眠模式,非系统休眠,暂时没实现,还不会跑到这里),则唤醒各个进程*/ @@ -397,7 +398,7 @@ public class CoreService extends Service { // if (!Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) // Util.turnOnWifiForConnect(runtime.getContextProxy().context, runtime); } - } else if ("android.intent.action.SCREEN_OFF".equals(param1Intent.getAction()) && Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) { + } else if ("android.intent.action.SCREEN_OFF".equals(intent.getAction()) && Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) { // CoreService.is_wifi_network_ok = true; if (!runtime.isNoTurnOffWifiOnScreenOff()) { //不关闭wifi when ScreenOff @@ -405,6 +406,16 @@ public class CoreService extends Service { // if (Util.isWifiIsOpen(runtime.getContextProxy().context,runtime)) // Util.turnOffWifiForSleep(runtime.getContextProxy().context, runtime); } + }else if (intent.getAction().equals("android.media.VOLUME_CHANGED_ACTION")) { + int streamType = intent.getIntExtra("android.media.EXTRA_VOLUME_STREAM_TYPE", -1); + ICLogger.i("Volume changed stream type "+streamType); + + int newVolume = intent.getIntExtra("android.media.EXTRA_VOLUME_STREAM_VALUE", 0); + int oldVolume = intent.getIntExtra("android.media.EXTRA_PREV_VOLUME_STREAM_VALUE", 0); + if (newVolume != oldVolume) { + ICLogger.i("Volume changed old "+oldVolume+" new "+newVolume); + Config.setMasterVolume(context,newVolume); + } } } }; @@ -853,6 +864,7 @@ public class CoreService extends Service { intentFilter = new IntentFilter(); intentFilter.addAction("android.intent.action.SCREEN_ON"); intentFilter.addAction("android.intent.action.SCREEN_OFF"); + intentFilter.addAction("android.media.VOLUME_CHANGED_ACTION"); (this.runtime.getContextProxy()).context.registerReceiver(this.screenOnReceiver, intentFilter); //注册接收 AT指令结果返回消息 @@ -940,6 +952,7 @@ public class CoreService extends Service { runtime.bleInfo.bleScanCycle=Config.getBleScanCycle(this); if(Config.BLEScanProtocol==1 && runtime.bleInfo.bleScanCycle>0) { + setBleScanAlarm(runtime.bleInfo.bleScanCycle); } @@ -1353,15 +1366,17 @@ public class CoreService extends Service { } public void setBleScanAlarm(int cycle){ + //只有蓝牙扫描协议1才需要设置周期,蓝牙扫描协议0 为心跳及定位时才进行扫描 if (Config.BLEScanProtocol!=1) { ICLogger.i("BLEScanProtocol!=1 skip setPolingCheckAntiAlarm"); return; } StringBuilder sb=new StringBuilder(); - if (cycle>1) { - AlarmHelper.setRealTimeAlarm(runtime.getContextProxy().context, cycle, ACTION_ALARM_BLE_SCAN); + if (cycle>=15) { + //由于蓝牙扫描一次15秒,所以周期要大于等于15秒 + AlarmHelper.setRealTimeAlarmInMicorSeconds(runtime.getContextProxy().context, cycle*1000, ACTION_ALARM_BLE_SCAN); } - sb.append("setBleScanAlarm " + cycle); + sb.append("setBleScanAlarm " + cycle+" seconds"); locationClient.triggerBLEProcess(); ICLogger.i(sb.toString()); if (Config.LOG_TOFILE)ICLogger.logToFile("alarmCycle",sb.toString());