Skip to content

Instantly share code, notes, and snippets.

@sidishere
Created December 24, 2019 11:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidishere/49becaa48fa9c59fe9963db536c73af5 to your computer and use it in GitHub Desktop.
Save sidishere/49becaa48fa9c59fe9963db536c73af5 to your computer and use it in GitHub Desktop.
private void Disconnect()
{
if (btSocket!=null) //If the btSocket is busy
{
try
{
btSocket.close(); //close connection
Toast.makeText(getApplicationContext(),"Connection closed successfully",Toast.LENGTH_SHORT).show();
}
catch (IOException e)
{
Toast.makeText(getApplicationContext(),"Error in closing connection",Toast.LENGTH_SHORT).show();
}
}
finish(); //return to the first layout
}
private void turnOffLed()
{
if (btSocket!=null)
{
try
{
btSocket.getOutputStream().write("TF".toString().getBytes());
}
catch (IOException e)
{
Toast.makeText(getApplicationContext(),"Error in sending command",Toast.LENGTH_SHORT).show();
}
}
}
private void turnOnLed()
{
if (btSocket!=null)
{
try
{
btSocket.getOutputStream().write("TO".toString().getBytes());
}
catch (IOException e)
{
Toast.makeText(getApplicationContext(),"Error in sending command",Toast.LENGTH_SHORT).show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment