Commit 884e14b840cba834ecf10c2311d3a07c9d9dceb2

Authored by 杨帅
1 parent 35113906

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

config.gradle
... ... @@ -21,7 +21,7 @@ ext {
21 21 //编译方式
22 22 debug : false,
23 23 //版本号
24   - version: "0.7.4",
  24 + version: "0.7.5",
25 25 //Lib库前缀
26 26 packeg : "com.cnlive.module",
27 27 //Lib库名称
... ...
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/receivers/CollServiceReceiver.java
... ... @@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
4 4 import android.content.BroadcastReceiver;
5 5 import android.content.Context;
6 6 import android.content.Intent;
  7 +import android.media.AudioManager;
7 8 import android.os.Build;
8 9 import android.os.PowerManager;
9 10 import android.util.Log;
... ... @@ -35,6 +36,9 @@ public class CollServiceReceiver extends BroadcastReceiver {
35 36 @Override
36 37 public void onReceive(Context context, Intent intent) {
37 38 Log.e(TAG, "接收到广播:" + intent.getAction());
  39 + if (null!=context){
  40 + initSound(context);
  41 + }
38 42 //todo 这里判断要保活的服务
39 43 boolean isRunStepService = CollCommonInfo.getIsRunStepService(context);
40 44 if (isRunStepService) {
... ... @@ -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 4 import android.content.BroadcastReceiver;
5 5 import android.content.Context;
6 6 import android.content.Intent;
  7 +import android.media.AudioManager;
7 8 import android.os.Build;
8 9 import android.os.PowerManager;
9 10 import android.util.Log;
... ... @@ -36,6 +37,9 @@ public class ServiceReceiver extends BroadcastReceiver {
36 37 @Override
37 38 public void onReceive(Context context, Intent intent) {
38 39 Log.e(TAG, "接收到广播:" + intent.getAction());
  40 + if (null != context) {
  41 + initSound(context);
  42 + }
39 43 //todo 这里判断要保活的服务
40 44 boolean isRunStepService = CommonInfo.getIsRunStepService(context);
41 45 if (isRunStepService) {
... ... @@ -45,7 +49,7 @@ public class ServiceReceiver extends BroadcastReceiver {
45 49 } else {
46 50 context.startService(new Intent(context, StepService.class));
47 51 }
48   - }else {
  52 + } else {
49 53 Log.e(TAG, "计步服务已经在运行");
50 54  
51 55 }
... ... @@ -56,7 +60,7 @@ public class ServiceReceiver extends BroadcastReceiver {
56 60 if (StepService.mClient != null && StepService.mTrace != null && StepService.traceListener != null) {
57 61 StepService.mClient.startTrace(StepService.mTrace, StepService.traceListener);
58 62 }
59   - }else {
  63 + } else {
60 64 Log.e(TAG, "鹰眼服务已经在运行");
61 65  
62 66 }
... ... @@ -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 // */
... ...