[MTK] Bluetooth 车载系统 > 获取手机电量 SIM卡信号 运营商等 Android6.0

版权声明:富就富在不知足,贵就贵在能脱俗。贫就贫在少见识,贱就贱在没骨气。 https://blog.csdn.net/qq_33544860/article/details/77988856

项目需求

需要在车载系统中通过蓝牙显示手机的电量信息 Sim卡信号 运营商


百度无解

1.除了厂商定制的蓝牙模块

2.除了看不懂的代码

3.就剩这个了(图片来源网路截图)



弱弱地问一下还要等多久? 至少哥的s7 android7.0还没发现有这个功能! android8.0呢?


自行阅读mtk Bluetooth 模块的源码


几天机夜终于看到了亮点.谢天谢地


--------------华丽的分割线---------------


重点:

1.相关类:HeadsetClientProfile

2.源码路径:/vendor/mediatek/proprietary/frameworks/base/bluetooth/java/com/autochips/bluetooth


在该类HeadsetClientProfile.java中可以看到:

    /**
     * Returns list of current values of AG indicators.(指示信号)
     *
     * @param device    remote device
     * @return          bundle of AG  indicators; null if device is not in
     *                  CONNECTED state
     */
    public Bundle getCurrentAgEvents(BluetoothDevice device) {
        if (mProxy != null ) {
            return mProxy.getCurrentAgEvents(device);
        }
        return null;
    }

解说:

Audio Gateway(AG,音频网关)AG是音频输入和输出的设备,典型的AG设备是手机


那么Bundle里面都有啥?

最简单方法直接去遍历(如下:)

                        Bundle remoDevInfo = hfProfile.getCurrentAgEvents(remoteDevice);
                        if (remoDevInfo == null) return;

                        Set<String> set = remoDevInfo.keySet();
                        if (set == null) return;
                        for (Iterator iterator = set.iterator(); iterator.hasNext(); ) {
                            String key = (String) iterator.next();
                            Object value = remoDevInfo.get(key);
                            Log.d("BTServicesss", "key:" + key + " value:" + value);
                        }
这然bundle中包含的key/value全都出来了

hfProfile对象和remoteDevice不会不知道怎么得到的你再call我吧(easy).

以下列出在终端打印出来的key/value:

key:android.bluetooth.headsetclient.extra.NETWORK_STATUS value:1
key:android.bluetooth.headsetclient.extra.VOICE_RECOGNITION value:0
key:android.bluetooth.headsetclient.extra.BATTERY_LEVEL value:4
key:android.bluetooth.headsetclient.extra.SUBSCRIBER_INFO value:
key:android.bluetooth.headsetclient.extra.OPERATOR_NAME value:中国移动
key:android.bluetooth.headsetclient.extra.IN_BAND_RING value:0
key:android.bluetooth.headsetclient.extra.NETWORK_ROAMING value:0
key:android.bluetooth.headsetclient.extra.NETWORK_SIGNAL_STRENGTH value:0
有了这些值 想干嘛就干嘛吧!key看不懂的百度,再看不懂的遍历源码搜索该key,再看不懂的call我

提示:

BATTERY_LEVEL这个值怎么去转化成电量百分几自行百度哈 都有!

                        [自己动手会更好]
---------------------超牛B的分割线-----------------


上文说的需要自己去获取,是不是有点坑?(那么手机信号改变了,如果可以通知我岂不是完美?)

TMD是有方法的!

最牛B的方法就是监听广播啦(直接上action,免得你们找半天):


action:android.bluetooth.headsetclient.profile.action.AG_EVENT


其实呢,上面的key/value都是通过这条广播发送过来的................

接下,知道key了(上面终端打印的)就可以直接通过intent.getExtras()获得bundle数据

从而通过key提取我们需要的东西的


有时间多看源码!


(感谢阅读)



猜你喜欢

转载自blog.csdn.net/qq_33544860/article/details/77988856