浏览代码

处理云教练的耳机监听broadcast,不需要service

Pq 7 月之前
父节点
当前提交
92b176013b
共有 1 个文件被更改,包括 4 次插入2 次删除
  1. 4 2
      BaseLibrary/src/main/java/com/cooleshow/base/service/PlayMusicReceiver.java

+ 4 - 2
BaseLibrary/src/main/java/com/cooleshow/base/service/PlayMusicReceiver.java

@@ -13,14 +13,16 @@ public class PlayMusicReceiver extends BroadcastReceiver {
         String action = intent.getAction();
         if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
             if (intent.hasExtra("state")) {
-                if (intent.getIntExtra("state", 0) == 0) {
+                int state = intent.getIntExtra("state", 0);
+                if (state == 0) {
                     //无耳机插入
                     Constants.HEADSET_PLUE_TAG = "";
-                } else if (intent.getIntExtra("state", 0) == 1) {
+                } else if (state == 1) {
                     //有耳机插入
                     Constants.HEADSET_PLUE_TAG = "有线耳机";
                 }
             }
         }
+
     }
 }