import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
-import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
* Activity in the result Intent.
*/
public class DeviceListActivity extends Activity {
- // Debugging
- private static final String TAG = "DeviceListActivity";
- private static final boolean D = true;
// Return Intent extra
public static final String EXTRA_DEVICE_ADDRESS = "device_address";
* Start device discover with the BluetoothAdapter
*/
private void doDiscovery() {
- if (D) Log.d(TAG, "doDiscovery()");
+ AltosDebug.debug("doDiscovery()");
// Indicate scanning in the title
setProgressBarIndeterminateVisibility(true);
else
name = info;
- if (D) Log.d(TAG, String.format("******* selected item '%s'", info));
+ AltosDebug.debug("******* selected item '%s'", info);
// Create the result Intent and include the MAC address
Intent intent = new Intent();
// When discovery finds a device
if (BluetoothDevice.ACTION_FOUND.equals(action)) {
- // Get the BluetoothDevice object from the Intent
+
+ /* Get the BluetoothDevice object from the Intent
+ */
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
- // If it's already paired, skip it, because it's been listed already
- if ( device.getBondState() != BluetoothDevice.BOND_BONDED
- && device.getName().startsWith("TeleBT") ) {
- mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
+
+ /* If it's already paired, skip it, because it's been listed already
+ */
+ if (device != null && device.getBondState() != BluetoothDevice.BOND_BONDED)
+ {
+ String name = device.getName();
+ if (name != null && name.startsWith("TeleBT"))
+ mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
}
- // When discovery is finished, change the Activity title
+
+ /* When discovery is finished, change the Activity title
+ */
} else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
setProgressBarIndeterminateVisibility(false);
setTitle(R.string.select_device);