Commit 884e14b840cba834ecf10c2311d3a07c9d9dceb2

Authored by 杨帅
1 parent 35113906

1 修复vivo静音模式下保活失败的问题

config.gradle
@@ -21,7 +21,7 @@ ext { @@ -21,7 +21,7 @@ ext {
21 //编译方式 21 //编译方式
22 debug : false, 22 debug : false,
23 //版本号 23 //版本号
24 - version: "0.7.4", 24 + version: "0.7.5",
25 //Lib库前缀 25 //Lib库前缀
26 packeg : "com.cnlive.module", 26 packeg : "com.cnlive.module",
27 //Lib库名称 27 //Lib库名称
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/receivers/CollServiceReceiver.java
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint; @@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
4 import android.content.BroadcastReceiver; 4 import android.content.BroadcastReceiver;
5 import android.content.Context; 5 import android.content.Context;
6 import android.content.Intent; 6 import android.content.Intent;
  7 +import android.media.AudioManager;
7 import android.os.Build; 8 import android.os.Build;
8 import android.os.PowerManager; 9 import android.os.PowerManager;
9 import android.util.Log; 10 import android.util.Log;
@@ -35,6 +36,9 @@ public class CollServiceReceiver extends BroadcastReceiver { @@ -35,6 +36,9 @@ public class CollServiceReceiver extends BroadcastReceiver {
35 @Override 36 @Override
36 public void onReceive(Context context, Intent intent) { 37 public void onReceive(Context context, Intent intent) {
37 Log.e(TAG, "接收到广播:" + intent.getAction()); 38 Log.e(TAG, "接收到广播:" + intent.getAction());
  39 + if (null!=context){
  40 + initSound(context);
  41 + }
38 //todo 这里判断要保活的服务 42 //todo 这里判断要保活的服务
39 boolean isRunStepService = CollCommonInfo.getIsRunStepService(context); 43 boolean isRunStepService = CollCommonInfo.getIsRunStepService(context);
40 if (isRunStepService) { 44 if (isRunStepService) {
@@ -97,7 +101,16 @@ public class CollServiceReceiver extends BroadcastReceiver { @@ -97,7 +101,16 @@ public class CollServiceReceiver extends BroadcastReceiver {
97 101
98 } 102 }
99 } 103 }
100 - 104 + private void initSound(Context context) {
  105 + try {
  106 + AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  107 + int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
  108 + if (0 == currentVolume) {
  109 + audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 1, AudioManager.FLAG_PLAY_SOUND);
  110 + }
  111 + } catch (Exception e) {
  112 + }
  113 + }
101 // /** 114 // /**
102 // * 发送关闭广播 115 // * 发送关闭广播
103 // */ 116 // */
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/receivers/ServiceReceiver.java
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint; @@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
4 import android.content.BroadcastReceiver; 4 import android.content.BroadcastReceiver;
5 import android.content.Context; 5 import android.content.Context;
6 import android.content.Intent; 6 import android.content.Intent;
  7 +import android.media.AudioManager;
7 import android.os.Build; 8 import android.os.Build;
8 import android.os.PowerManager; 9 import android.os.PowerManager;
9 import android.util.Log; 10 import android.util.Log;
@@ -36,6 +37,9 @@ public class ServiceReceiver extends BroadcastReceiver { @@ -36,6 +37,9 @@ public class ServiceReceiver extends BroadcastReceiver {
36 @Override 37 @Override
37 public void onReceive(Context context, Intent intent) { 38 public void onReceive(Context context, Intent intent) {
38 Log.e(TAG, "接收到广播:" + intent.getAction()); 39 Log.e(TAG, "接收到广播:" + intent.getAction());
  40 + if (null != context) {
  41 + initSound(context);
  42 + }
39 //todo 这里判断要保活的服务 43 //todo 这里判断要保活的服务
40 boolean isRunStepService = CommonInfo.getIsRunStepService(context); 44 boolean isRunStepService = CommonInfo.getIsRunStepService(context);
41 if (isRunStepService) { 45 if (isRunStepService) {
@@ -45,7 +49,7 @@ public class ServiceReceiver extends BroadcastReceiver { @@ -45,7 +49,7 @@ public class ServiceReceiver extends BroadcastReceiver {
45 } else { 49 } else {
46 context.startService(new Intent(context, StepService.class)); 50 context.startService(new Intent(context, StepService.class));
47 } 51 }
48 - }else { 52 + } else {
49 Log.e(TAG, "计步服务已经在运行"); 53 Log.e(TAG, "计步服务已经在运行");
50 54
51 } 55 }
@@ -56,7 +60,7 @@ public class ServiceReceiver extends BroadcastReceiver { @@ -56,7 +60,7 @@ public class ServiceReceiver extends BroadcastReceiver {
56 if (StepService.mClient != null && StepService.mTrace != null && StepService.traceListener != null) { 60 if (StepService.mClient != null && StepService.mTrace != null && StepService.traceListener != null) {
57 StepService.mClient.startTrace(StepService.mTrace, StepService.traceListener); 61 StepService.mClient.startTrace(StepService.mTrace, StepService.traceListener);
58 } 62 }
59 - }else { 63 + } else {
60 Log.e(TAG, "鹰眼服务已经在运行"); 64 Log.e(TAG, "鹰眼服务已经在运行");
61 65
62 } 66 }
@@ -99,6 +103,16 @@ public class ServiceReceiver extends BroadcastReceiver { @@ -99,6 +103,16 @@ public class ServiceReceiver extends BroadcastReceiver {
99 } 103 }
100 } 104 }
101 105
  106 + private void initSound(Context context) {
  107 + try {
  108 + AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  109 + int currentVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
  110 + if (0 == currentVolume) {
  111 + audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 1, AudioManager.FLAG_PLAY_SOUND);
  112 + }
  113 + } catch (Exception e) {
  114 + }
  115 + }
102 // /** 116 // /**
103 // * 发送关闭广播 117 // * 发送关闭广播
104 // */ 118 // */