| Author |
bluetooth and sms together
|
mabel foo
Greenhorn
Joined: Oct 07, 2009
Posts: 8
|
|
can somebody enlighten me on how to run a bluetooth device search and wait for receiving sms at the same time? i need these 2 to be running simultaneously.. or at least be able to work together effectively.
whenever i run the command "msg = smsconn.receive()" , it will stop here and won't be able to continue to run the bluetooth commands anymore.
hope you guys can guide me along.. thanks!
|
 |
Srinath Gamage
Ranch Hand
Joined: Jun 19, 2008
Posts: 40
|
|
HI,
If you are using con.receive(),use it in a separate thread.Better way is to use MessageListener Interface, as it is non-blocking.
Hope this will help you.
For more info , read MessageListener
|
SCJP & SCMAD
http://srinathbugz.blogspot.com/
|
 |
mabel foo
Greenhorn
Joined: Oct 07, 2009
Posts: 8
|
|
hey! thanks alot! your info really helped me.
but how do i access the contents of the sms if i use the messagelistener? becos i need to check the content of the sms to set a certain condition.
when i was using con.receive(), i accessed the code this way:
if (smsconn.receive() != null) {
//get contents of sms
}
|
 |
Srinath Gamage
Ranch Hand
Joined: Jun 19, 2008
Posts: 40
|
|
Hi,
As you may have understood by reading above link, when a SMS receives MessageListener invokes notifyIncomingMessage(Conn) method. So in that method notify another thread which you have message reading
code. Use smsconn.receive() there as usual, and you don;t have to check for null, as logic comes to here only if
you are notified by a incoming SMS. Read this article,
it shows real code with threading for MessageListener ( "A Real-Life Example" - Last heading in article ).
|
 |
mabel foo
Greenhorn
Joined: Oct 07, 2009
Posts: 8
|
|
Thanks! I've made use of the reference you gave. (:
Now i have another problem. when i do a bluetooth search for a certain device, the application will send a sms out. i created a new thread to send the sms out. but there is always this exception (java.lang.illegalargumentexception: host format) which i don't know what is causing it. can you help me here?
|
 |
mabel foo
Greenhorn
Joined: Oct 07, 2009
Posts: 8
|
|
|
hey! i solved the error already. it was actually a careless mistake on my part. (:
|
 |
Srinath Gamage
Ranch Hand
Joined: Jun 19, 2008
Posts: 40
|
|
Good luck
|
 |
 |
|
|
subject: bluetooth and sms together
|
|
|