简体   繁体   中英

Auto-Connectivity with Bluetooth Device to Android Phone

I am using a Bluetooth device to connect with the android Phone manually there is no problem. But My Question is how can I connect automatically when I starts my Activity or Application .
I am taking the reference of Bluetooth chat in Sample API to connect. http://developer.android.com/resources/samples/BluetoothChat/index.html

Please Suggest me.

By the default API example, I get the same problem : when connecting each other more 5 seconds, it will lost automatically However, finally, I found that I put a finish() in the onCreate() method for debugging. when I take it off, it works fine all the time that sending data to the bluetooth chat demo.

it does not require discovery. and if will pair up the first time, and next time, it will just send directly

the most important code as following:

mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    BluetoothDevice device = mBluetoothAdapter
            .getRemoteDevice("6C:83:36:A0:0E:89");

    new ConnectThread(device).start();

ConnectThread can be found in the Android Demo API: http://developer.android.com/guide/topics/connectivity/bluetooth.html

Yes you can achieve this using Bluetooth API. First of all you need to get that Device's Address. Now in activity you need to make it hardcode(static) for connection. you can write code in OnCreate() Method of Activity for Automatic Connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM