Fórum InputStream em comunicação bluetooth #571625
25/11/2016
0
Olá pessoal! Sou iniciante no mundo do desenvolvimento. Estou tentando montar uma aplicação que receba dados via bluetooth do arduino. Quero enviar dados que possam ser exibidos no aplicativo android por um textview. Na questão da comunicação com o socket eu já consegui, o problema é que talvez não esteja sabendo utilizar do jeito certo o inputstream ou a thread de execução para leitura dos dados. Preciso de ajuda. Segue dados:
if (meuSocket != null) {
try {
inputStream = meuSocket.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
new Thread () {
@Override
public void run() {
running = true;
byte[] bytes = new byte[1024];
int length;
while (running){
try {
length = inputStream.read(bytes);
String msg = new String(bytes, 0, length);
variavel.setText(msg);
variavel.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
try {
variavel.setText(s);
final int numero = Integer.parseInt(variavel.getText().toString());
mProgressbar.setProgress(numero);
}
catch(Exception error){
variavel.setText(s);
mProgressbar.setProgress(0);
};
}
@Override
public void afterTextChanged(Editable s) {
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.start();
Whermerson Marques
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)