make quit button work by letting BtSocketIoThread actually leave its main loop, do not display "Unknown" for unknown numbers but the number itself.

master
Andreas Shimokawa 2015-01-31 11:49:46 +01:00
parent 8e69723931
commit c0bfe2f715
1 changed files with 8 additions and 2 deletions

View File

@ -150,6 +150,7 @@ public class BluetoothCommunicationService extends Service {
super.onDestroy(); super.onDestroy();
if (mBtSocketIoThread != null) { if (mBtSocketIoThread != null) {
try { try {
mBtSocketIoThread.quit();
mBtSocketIoThread.join(); mBtSocketIoThread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
@ -172,7 +173,7 @@ public class BluetoothCommunicationService extends Service {
private String getContactDisplayNameByNumber(String number) { private String getContactDisplayNameByNumber(String number) {
Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
String name = "Unknown"; String name = number;
if (number == null || number.equals("")) { if (number == null || number.equals("")) {
return name; return name;
@ -233,6 +234,7 @@ public class BluetoothCommunicationService extends Service {
private class BtSocketIoThread extends Thread { private class BtSocketIoThread extends Thread {
private final InputStream mmInStream; private final InputStream mmInStream;
private final OutputStream mmOutStream; private final OutputStream mmOutStream;
private boolean mQuit = false;
public BtSocketIoThread(InputStream instream, OutputStream outstream) { public BtSocketIoThread(InputStream instream, OutputStream outstream) {
mmInStream = instream; mmInStream = instream;
@ -243,7 +245,7 @@ public class BluetoothCommunicationService extends Service {
byte[] buffer = new byte[8192]; byte[] buffer = new byte[8192];
int bytes; int bytes;
while (true) { while (!mQuit) {
try { try {
bytes = mmInStream.read(buffer, 0, 4); bytes = mmInStream.read(buffer, 0, 4);
if (bytes < 4) if (bytes < 4)
@ -296,5 +298,9 @@ public class BluetoothCommunicationService extends Service {
} catch (IOException e) { } catch (IOException e) {
} }
} }
public void quit() {
mQuit = true;
}
} }
} }