1. 程式人生 > 實用技巧 >Android藍芽讀取簡訊調研

Android藍芽讀取簡訊調研

1、無法得到BluetoothMasClient類

在文章https://blog.csdn.net/u012439416/article/details/54349812(藍芽map協議原始碼解析)這篇文章中有提到通過MAP方式來實現藍芽讀取簡訊,其中有個比較關鍵的類BluetoothMasClient,但在API-27(Android8.1)及以上系統都無法獲取到。

(1)API-27上無法直接引用BluetoothMasClient類

在系統原始碼frameworks\opt\bluetooth\src\android\bluetooth\client\map下可以找到該類,引用路徑為"android.bluetooth.client.map.BluetoothMasClient",使用時發現無法引用這個類。

(2)在API-27(Android8.1)無法通過反射獲取到BluetoothMasClient類

通過反射的方式,也無法獲取到該類。測試程式碼:

 1 public void getBluetoothMasClient() {
 2     Log.d(TAG, "testGetHide");
 3     try {
 4         Class<?> c = Class.forName("android.bluetooth.client.map.BluetoothMasClient");
 5         Log.d(TAG, "name=" + c.getName());
6 } catch (ClassNotFoundException e) { 7 Log.d(TAG, "e=" + e.getMessage()); 8 e.printStackTrace(); 9 } 10 }

執行結果:

 1  W/System.err: java.lang.ClassNotFoundException: android.bluetooth.client.map.BluetoothMasClient
 2  W/System.err:     at java.lang.Class.classForName(Native Method)
3 W/System.err: at java.lang.Class.forName(Class.java:453) 4 W/System.err: at java.lang.Class.forName(Class.java:378) 5 W/System.err: at com.example.demo.sms.BTActivity.testGetHide(BTActivity.java:489) 6 W/System.err: at com.example.demo.sms.BTActivity.onCreate(BTActivity.java:73) 7 W/System.err: at android.app.Activity.performCreate(Activity.java:7050) 8 W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) 9 W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2809) 10 W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2931) 11 W/System.err: at android.app.ActivityThread.-wrap11(Unknown Source:0) 12 W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1620) 13 W/System.err: at android.os.Handler.dispatchMessage(Handler.java:105) 14 W/System.err: at android.os.Looper.loop(Looper.java:176) 15 W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6701) 16 W/System.err: at java.lang.reflect.Method.invoke(Native Method) 17 W/System.err: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:249) 18 W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:783)

(3)API-28(Android9.0)上該類已經不存在了

在AS中搜索該類,以及在系統原始碼中按照之前的路徑,都無法再找到該類。