0

酸素濃度計、体温計、体重計などの「Bluetoothヘルスデバイス」からAndroidフォンの(データ)読み取り値をキャプチャしようとしています。デバイスを電話に接続できますが、データを読み取ろうとするとスタックしましたあそこだけ。私は次の手順を実行しています..(Android 2.2)最初にソケット接続を作成しています

  1. BluetoothSocket Socket.connect();// for socket connection-----done successfully

  2. BluetoothSocket tmp= device.createRfcommSocketToServiceRecord(MY_UUID);//ここ MY_UUID="00001101-0000-1000-8000-00805F9B34FB";

  3. 読んだスレッドで

    byte[] buffer = new byte[37];// i think here I am not getting exact bytes

    int bufferBytes = 0, bufferIndex = 0;

        Log.e(TAG, "MESSAGE_READ....");
        Communications comms = null;
        Bundle bundle = new Bundle();
        try {
             comms = new Communications();
             Log.e(TAG, "After Communications....");
    
        } catch (Exception e) {
            Log.e(TAG, "Error in communicaton....");
        }
    
    
        // Keep listening to the InputStream while connected
        while (true) {
    
            Log.e(TAG, "Its coming in while");
            try {
    
                try {
                    bufferBytes = mmInStream.read(buffer);// the code stuck here its not going down till health device get off(its directly jump to exception after device get off)
                } catch (IndexOutOfBoundsException e) {
                    Log.e(TAG, "bufferBytes error ====== +e.getMessage());
                }
    
    
    
                //Log.e(TAG, "bufferBytes====== "+bufferBytes);
                while (bufferBytes > bufferIndex) {
    
                    String[] message = comms.receiveMessage(buffer,
                            bufferIndex, bufferBytes);
                    bufferIndex = Integer.parseInt(message[1]);
                    Log.e(TAG, "bufferIndex====== "+bufferIndex);
                    if (message[0] != null) {
    
                        /*
                         * Processing message sent by device
                         */
                        StringTokenizer dataInTokens = new StringTokenizer(
                                message[0]);
    
                        if (dataInTokens.hasMoreTokens() == true) {
    
                            String token = dataInTokens.nextToken();
                            Log.e(TAG, "token====== "+token);
                            if (token.equals("a")) {
    
                                int weight = 0;
                                if (dataInTokens.hasMoreTokens() == true) {
    
                                    weight = Integer.parseInt(dataInTokens
                                            .nextToken());
    
                                    // Send a message back to the Activity
                                    msg = mHandler
                                            .obtainMessage(ScaleActivity.MESSAGE_READ);
                                    bundle.putInt(ScaleActivity.WEIGHT,
                                            weight);
                                    msg.setData(bundle);
                                    mHandler.sendMessage(msg);
                                }
                            } else if (token.equals("b")) {
    
                                int weight = 0;
                                if (dataInTokens.hasMoreTokens() == true) {
    
                                    weight = Integer.parseInt(dataInTokens
                                            .nextToken());
    
                                    // Send a message back to the Activity
                                    msg = mHandler
                                            .obtainMessage(ScaleActivity.MESSAGE_READ);
                                    bundle.putInt(
                                            ScaleActivity.WEIGHT_TO_SAVE,
                                            weight);
                                    msg.setData(bundle);
                                    mHandler.sendMessage(msg);
                                }
                            }
                        }
                    }
                }
    

また、Android 4.0 HDP Example も試しました。これはこちらから入手できます が、当社のヒース デバイスは hdp に対応していません。だから私にとってもうまくいきません。

4

1 に答える 1

1

私もまったく同じ状況です。接続を確立し、SSP プロファイル (UUID 00001101-0000-1000-8000-00805F9B34FB) を使用してソケットを作成できました。このリフレクション コードを実行して、Bluetooth Health デバイスが SSP サービスを公開していることを確認しました (デバイス公開 UUID を取得するメソッドは、この API レベルに隠されています)。

Class<?> cl = Class.forName("android.bluetooth.BluetoothDevice");
Method method = cl.getMethod("getUuids");
Object retval = method.invoke(myBTDevice);

(retval には、接続できる有効な UUID デバイス サービスの配列が含まれています。)

問題は、何かを読み取ろうとする前に、一連のコマンドをデバイスに送信する必要があることです。そうしないと、読み取りメソッドが永久にハングします。私はこの隠されたプロトコルを理解しようと数日間グーグルで検索しましたが、成功しませんでした。メーカー名とモデルでも検索しましたが、何もありません(DigiFox Fingertip pulse oximeter)。

私の唯一の希望は、デバイスと正常に通信し、測定値を読み取ることができる Windows で実行されるカスタム ソフトウェアがデバイスと共に提供されることです。何かを読み取る前に、何らかの Bluetooth アナライザーまたはパケット スニファーを使用して、デバイスに送信されるデータをチェックする必要がある場合があります。私がそれを機能させることができれば、ここに投稿します。

よろしく。

于 2012-08-14T13:12:15.723 に答える