Jump to content

Android bluetooth connection

Samskip
Go to solution Solved by madknight3,

Thanks for your reply. And yes that was my idea aswell but you have to work with input and output streams. And the only thing i know that is usefull for is for sending files or stuff like that.So no idea how i should send some kind of a signal via that.

I've worked with Tcp/Udp but I'm not familiar with bluetooth. I can't say for sure but if you can transfer files, which is basically just an array of bytes, there's no reason to think you can't transfer your own byte/byte array.

 

You might only need a single byte to represent a command

commandByte = 1; // Represents command 1 (An Enum or something can be used to define the commands in a readable way)

Or if you need to transfer more information along with it, maybe a byte array like this would be better

commandByteArray[0] //could identify a commandcommandByteArray[1 to 4] //could be an integer (4 bytes) representing the length of total bytes needed to be readcommandByteArray[5 to 8] // could be an integer representing the ID of the sending device/usercommandByteArray[9+] //could be any additional data (if needed)

Unfortunately I can't really provide any help in how to use the streams to send/receive this info but if you can do it with files, I'm sure you can get it done with your own data.

Hi, im trying to create an android app that uses bluetooth.

I've got my connection set up and can send files from one device to another.

But i wondered if it was possible to invoke a method on device 1 by pressing a button on device 2?

Any advice is welcome.  :P

Intel i7-870  //  MSI GTX 670 PE       ///       Intel i7-4500U  //  GT720M

Link to comment
Share on other sites

Link to post
Share on other sites

I would imagine you can have a listener set up in your app than accepts a command and runs a method. Then you just have device 1 send command A, and when device 2 gets command A it'll run method A.

Link to comment
Share on other sites

Link to post
Share on other sites

I would imagine you can have a listener set up in your app than accepts a command and runs a method. Then you just have device 1 send command A, and when device 2 gets command A it'll run method A.

Thanks for your reply. And yes that was my idea aswell but you have to work with input and output streams. And the only thing i know that is usefull for is for sending files or stuff like that.So no idea how i should send some kind of a signal via that.

Intel i7-870  //  MSI GTX 670 PE       ///       Intel i7-4500U  //  GT720M

Link to comment
Share on other sites

Link to post
Share on other sites

You may find that you may need root access to be able to get it to do the send.

Link to comment
Share on other sites

Link to post
Share on other sites

Thanks for your reply. And yes that was my idea aswell but you have to work with input and output streams. And the only thing i know that is usefull for is for sending files or stuff like that.So no idea how i should send some kind of a signal via that.

I've worked with Tcp/Udp but I'm not familiar with bluetooth. I can't say for sure but if you can transfer files, which is basically just an array of bytes, there's no reason to think you can't transfer your own byte/byte array.

 

You might only need a single byte to represent a command

commandByte = 1; // Represents command 1 (An Enum or something can be used to define the commands in a readable way)

Or if you need to transfer more information along with it, maybe a byte array like this would be better

commandByteArray[0] //could identify a commandcommandByteArray[1 to 4] //could be an integer (4 bytes) representing the length of total bytes needed to be readcommandByteArray[5 to 8] // could be an integer representing the ID of the sending device/usercommandByteArray[9+] //could be any additional data (if needed)

Unfortunately I can't really provide any help in how to use the streams to send/receive this info but if you can do it with files, I'm sure you can get it done with your own data.

Link to comment
Share on other sites

Link to post
Share on other sites

I've worked with Tcp/Udp but I'm not familiar with bluetooth. I can't say for sure but if you can transfer files, which is basically just an array of bytes, there's no reason to think you can't transfer your own byte/byte array.

 

You might only need a single byte to represent a command

commandByte = 1; // Represents command 1 (An Enum or something can be used to define the commands in a readable way)

Or if you need to transfer more information along with it, maybe a byte array like this would be better

commandByteArray[0] //could identify a commandcommandByteArray[1 to 4] //could be an integer (4 bytes) representing the length of total bytes needed to be readcommandByteArray[5 to 8] // could be an integer representing the ID of the sending device/usercommandByteArray[9+] //could be any additional data (if needed)

Unfortunately I can't really provide any help in how to use the streams to send/receive this info but if you can do it with files, I'm sure you can get it done with your own data.

Thank you for the idea, converting strings into byte arrays and converting them back on the other side works pretty well.

Intel i7-870  //  MSI GTX 670 PE       ///       Intel i7-4500U  //  GT720M

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×