0

I need to read a bluetooth stream for 5 seconds, because I need to be sure my app will get the bluetooth message (which is actually just a char casted to int). If my app can't read the message my btState variable is set to a certain value for another task.

while(btState!=666)
{
  btState=666;
    try {                       
        while(timestart-timenow<5){ //how do i do this?
            btState=mConnectThread.checkstate();
            mConnectThread.sendSignal('s');
         }
    } catch (Exception e) {break; }
}
Komal12
  • 3,340
  • 4
  • 16
  • 25
Lucas
  • 35
  • 1
  • 5
  • 4
    "How do i get current system time in android?" -- `System.currentTimeMillis()`. – CommonsWare May 09 '16 at 13:56
  • @Lucas please next time try googling first! https://www.google.at/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=get+current+time+android – CherryDT May 09 '16 at 14:35

1 Answers1

0

You could use:

Calendar c = Calendar.getInstance(); int seconds = c.get(Calendar.SECOND);

Documentation for the Calendar class

Have a look at this thread: Get current time and date on Android that asks pretty much the same question for more suggestions.

Credits to user658042 for the answer.

Community
  • 1
  • 1
Neil P.
  • 1,026
  • 2
  • 15
  • 32