Bluetooth data transfer between two Android devices

后端 未结 5 1047
盖世英雄少女心
盖世英雄少女心 2021-02-01 10:19

I have been following this Android guide for Bluetooth communication

To explain exactly what I want to do, when the two devices are paired, two different activities ope

5条回答
  •  悲&欢浪女
    2021-02-01 10:29

    mHandler is used for passing message from your BluetoothHandle.java to your Activity. This will help you to update messages on your screen which are returned by BluetoothHandler.

    you have to create mHandler from your activity and call your handler like this -

    mBluetoothHandler = new BluetoothHandler(this, mHandler);

    and your BluetoothHandler.java has constructor like this -

    public class BluetoothHandler { 
    
        public BluetoothHandler(Context context, Handler handler) {
                mAdapter = BluetoothAdapter.getDefaultAdapter();
                mState = STATE_NONE;
                mHandler = handler;
                mcontext = context;
       }
    
    }
    

    For more details, please refer Android sample project of Bluetooth Chat . You can also use this link : http://myandroidappdevelop.blogspot.in/2013/05/bluetooth-chat-example.html

提交回复
热议问题