Kaydet (Commit) cb6d2ed2 authored tarafından Andrzej J.R. Hunt's avatar Andrzej J.R. Hunt

Repeat bluetooth discovery periodically.

Change-Id: I2cccc3118a06b2202a249ae8ed116d2c3bc85395
üst e11ae67c
...@@ -11,6 +11,7 @@ import android.content.BroadcastReceiver; ...@@ -11,6 +11,7 @@ import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Handler;
import android.support.v4.content.LocalBroadcastManager; import android.support.v4.content.LocalBroadcastManager;
public class BluetoothFinder { public class BluetoothFinder {
...@@ -18,8 +19,6 @@ public class BluetoothFinder { ...@@ -18,8 +19,6 @@ public class BluetoothFinder {
// TODO: add removal of cached items // TODO: add removal of cached items
private Context mContext; private Context mContext;
private static final String CHARSET = "UTF-8";
BluetoothAdapter mAdapter; BluetoothAdapter mAdapter;
public BluetoothFinder(Context aContext) { public BluetoothFinder(Context aContext) {
...@@ -64,8 +63,6 @@ public class BluetoothFinder { ...@@ -64,8 +63,6 @@ public class BluetoothFinder {
@Override @Override
public void onReceive(Context context, Intent aIntent) { public void onReceive(Context context, Intent aIntent) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
System.out.print("Received intent<<<");
System.out.println(aIntent.getAction());
if (aIntent.getAction().equals(BluetoothDevice.ACTION_FOUND)) { if (aIntent.getAction().equals(BluetoothDevice.ACTION_FOUND)) {
BluetoothDevice aDevice = (BluetoothDevice) aIntent.getExtras() BluetoothDevice aDevice = (BluetoothDevice) aIntent.getExtras()
.get(BluetoothDevice.EXTRA_DEVICE); .get(BluetoothDevice.EXTRA_DEVICE);
...@@ -79,45 +76,17 @@ public class BluetoothFinder { ...@@ -79,45 +76,17 @@ public class BluetoothFinder {
CommunicationService.MSG_SERVERLIST_CHANGED); CommunicationService.MSG_SERVERLIST_CHANGED);
LocalBroadcastManager.getInstance(mContext).sendBroadcast( LocalBroadcastManager.getInstance(mContext).sendBroadcast(
aNIntent); aNIntent);
// System.out.println("Found " + aDevice.getName()); } else if (aIntent.getAction().equals(
// try { BluetoothAdapter.ACTION_DISCOVERY_FINISHED)) {
// // "f36d0a20-e876-11e1-aff1-0800200c9a66" // Start discovery again after a small delay.
// BluetoothSocket aSocket = aDevice Handler aHandler = new Handler();
// .createRfcommSocketToServiceRecord(UUID aHandler.postDelayed(new Runnable() {
// .fromString("00001101-0000-1000-8000-00805F9B34FB")); @Override
// aSocket.connect(); public void run() {
// } catch (IOException e) { mAdapter.startDiscovery();
// // TODO Auto-generated catch block }
// e.printStackTrace(); }, 1000 * 15);
// System.out.println("Fallback"); ;
// Method m;
// try {
// m = aDevice.getClass().getMethod("createRfcommSocket",
// new Class[] { int.class });
// BluetoothSocket aFSocket = (BluetoothSocket) m.invoke(
// aDevice, 1);
//
// mAdapter.cancelDiscovery();
// aFSocket.connect();
// } catch (NoSuchMethodException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// } catch (IllegalArgumentException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// } catch (IllegalAccessException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// } catch (InvocationTargetException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// } catch (IOException e1) {
// // TODO Auto-generated catch block
// e1.printStackTrace();
// }
// System.out.println("Fallback complete");
//
// }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment