user2317020
user2317020

Reputation: 21

How to Send AT commands to Android phone?

I have 2 android phones connected with each other via Bluetooth and am able to communicate between them using the BluetoothChat example (using the input/output stream)

I am also able to make a Bluetooth connection between these phones using the HandsFreeProfile by using the following UUID for connection:

    private static final UUID MY_UUID = 
                  UUID.fromString("0000111F-0000-1000-8000-00805F9B34FB"); 
                  // UUID for Hands free profile 

Now I want to send AT commands to one phone(Phone-B) from the other(Phone-A). I can send the command from phone-A to phone-B as String (using input/output streams) and receive it by the phone-B, but I do NOT know how to apply the incoming AT command on phone-B i.e. I don't know how to make phone-B do what AT command wants it to do.

I have read about the intent

android.bluetooth.BluetoothHeadset.ACTION_VENDOR_SPECIFIC_HEADSET_EVENT

but I'm not sure how to use this to send AT commands to the phone coz to use the intent some EXTRAS and a CATEGORY needs to be sent and I'm not sure what to send in those. For example below is the excerpt from the android website for the above intent:

*This intent will have 4 extras and 1 category.

EXTRA_DEVICE - The remote Bluetooth Device EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD - The vendor specific command EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_CMD_TYPE - The AT command type which can be one of AT_CMD_TYPE_READ, AT_CMD_TYPE_TEST, or AT_CMD_TYPE_SET, AT_CMD_TYPE_BASIC,AT_CMD_TYPE_ACTION. EXTRA_VENDOR_SPECIFIC_HEADSET_EVENT_ARGS - Command arguments.*

I'll really appreciate if someone can help me out and tell me :

  1. Can AT commands be reliably sent between 2 android phones in this way

  2. Post some code to demonstrate how to do this?

Thanks in advance!

Upvotes: 2

Views: 7634

Answers (1)

eliasj
eliasj

Reputation: 316

See my answer on this question:

How to send AT commands based on BT Hands-Free profile in android?

Hope that was the answer you was after.

Upvotes: 1

Related Questions