public
class
bReceiver
extends
BroadcastReceiver
{
BluetoothAdapter bAdapter;
BluetoothDevice bDevice;
@Override
public
void
onReceive(Context context, Intent intent)
{
String action = intent.getAction();
bAdapter = BluetoothAdapter.getDefaultAdapter();
if
(bAdapter.getState()==BluetoothAdapter.STATE_TURNING_ON
||bAdapter.getState()==BluetoothAdapter.STATE_ON)
{
Log.d(
"bluettoh is on"
,
"popup"
);
Intent intents =
new
Intent(context, MainActivity.
class
);
intents.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intents);
}
else
if
(bAdapter.getState()==BluetoothAdapter.STATE_TURNING_OFF)
{
Log.d(
"bluetooth is off"
,
"not popup"
);
}
else
if
(BluetoothDevice.ACTION_FOUND.equals(action))
{
Log.d(
"BluetoothDevice is found"
,
"not popup"
);
bDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if
(bDevice.getBondState()!=BluetoothDevice.BOND_BONDED)
{
Log.d(
"not bonded"
,
"......"
);
}
}
else
if
(BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action))
{
bAdapter.cancelDiscovery();
bDevice = bAdapter.getRemoteDevice(bDevice.getAddress());
Log.d(
"............"
,bDevice.getName()+
"/"
+bDevice.getAddress());
}
else
if
(BluetoothDevice.ACTION_BOND_STATE_CHANGED.equals(action))
{
Log.d(
"gggggg"
,
"gggggg"
);
}
else
if
(bDevice.getBondState()==BluetoothDevice.BOND_NONE)
{
Log.d(
"11"
,
"11"
);
}
else
if
(bDevice.getBondState()==BluetoothDevice.BOND_BONDING)
{
Log.d(
"22"
,
"22"
);
}
else
if
(bDevice.getBondState()==BluetoothDevice.BOND_BONDED)
{
Log.d(
"33"
,
"33"
);
Intent intents =
new
Intent(context, MainActivity.
class
);
intents.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intents);
}
}
};