• Android4.0-4.4 加入支持状态栏显示耳机图标方法(支持带不带MIC的两种耳机自己主动识别)


    效果如图:



    一、 在frameworks/base/packages/SystemUI/res/values/strings.xml 里加入

             

    1. <string name="headset_enabled">Headset Enabled.</string>  

    二、 在fameworks/base/core/res/res/values/config.xml 里对应位置加入:

    1. @@ -45,6 +45,7 @@  
    2.         <item><xliff:g id="id">alarm_clock</xliff:g></item>  
    3.         <item><xliff:g id="id">secure</xliff:g></item>  
    4.         <item><xliff:g id="id">clock</xliff:g></item>  
    5. +       <item><xliff:g id="id">headset</xliff:g></item>  
    6.      </string-array>  


    上面带+号的行为加入的


    三、 frameworks/base/packages/SystemUI/res/drawable-xhdpi 或者你手机相应的分辨率的目录下加入stat_sys_headset.png和stat_sys_headset_mic.png

    两个图片, 分别表示不带mic的耳机和带mic的耳机, 这两个图标将在状态栏显示, 图片能够自己找,也能够从fameworks/base/core/res/res/drawable-xhdpi里面提取现成的


    四、 在frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java 打上以下的补丁:


    1. --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java  
    2. +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java  
    3. @@ -103,6 +103,9 @@ public class PhoneStatusBarPolicy {  
    4.              else if (action.equals(TtyIntent.TTY_ENABLED_CHANGE_ACTION)) {  
    5.                  updateTTY(intent);  
    6.              }  
    7. +            else if (action.equals(Intent.ACTION_HEADSET_PLUG)) {  
    8. +                updateHeadset(intent);  
    9. +            }  
    10.          }  
    11.      };  
    12.    
    13. @@ -119,6 +122,7 @@ public class PhoneStatusBarPolicy {  
    14.          filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED);  
    15.          filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);  
    16.          filter.addAction(TtyIntent.TTY_ENABLED_CHANGE_ACTION);  
    17. +        filter.addAction(Intent.ACTION_HEADSET_PLUG);  
    18.          mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);  
    19.    
    20.          int numPhones = MSimTelephonyManager.getDefault().getPhoneCount();  
    21. @@ -276,4 +280,29 @@ public class PhoneStatusBarPolicy {  
    22.              mService.setIconVisibility("tty"false);  
    23.          }  
    24.      }  
    25. +  
    26. +    private final void updateHeadset(Intent intent) {  
    27. +        final String action = intent.getAction();  
    28. +        final int state = intent.getIntExtra("state", 4);  
    29. +        final int mic = intent.getIntExtra("microphone", 4);  
    30. +  
    31. +        switch (state) {  
    32. +        case 0:  
    33. +            try{  
    34. +                mService.setIconVisibility("headset"false);  
    35. +            } catch (Exception e) {  
    36. +                //Log.i("StatusBar Headset", "frist time to run");  
    37. +                }  
    38. +        break;  
    39. +        case 1:  
    40. +            if (mic == 1)  
    41. +                mService.setIcon("headset", R.drawable.stat_sys_headset_mic, 0,  
    42. +                    mContext.getResources().getString(R.string.headset_enabled));  
    43. +            else  
    44. +                mService.setIcon("headset", R.drawable.stat_sys_headset, 0,  
    45. +                    mContext.getResources().getString(R.string.headset_enabled));  
    46. +            mService.setIconVisibility("headset"true);  
    47. +        break;  
    48. +        }  
    49. +    }  
    50.  }  




    smali版本号參考本人github上的lewa的patchrom代码:

    https://github.com/syhost/lewa_patchrom_ef65l/commit/202a790d5c3e4dfb8fdfb6e837d96fd69e79d448


    当然要结合上面的源代码, 只作为參考 由于跟你的smali代码应该会差异非常大

  • 相关阅读:
    Linq to OBJECT延时标准查询操作符
    LINQ to XML
    动态Linq(结合反射)
    HDU 1242 dFS 找目标最短路
    HDu1241 DFS搜索
    hdu 1224 最长路
    BOJ 2773 第K个与m互质的数
    ZOJ 2562 反素数
    2016 ccpc 杭州赛区的总结
    bfs UESTC 381 Knight and Rook
  • 原文地址:https://www.cnblogs.com/zsychanpin/p/6971689.html
Copyright © 2020-2023  润新知