mis estimados como puedo hacer que cuando dos dispositivos esten conectados y uno de ellos de repente se desconecte vibre el celular
estoy utilizando BroadcastReceiver pero no me funciona ,este es mi codigo,igual y tengo pensado que se active un sonido junto con la vibracion
Código Java:
Ver originalprivate final BroadcastReceiver bReceiver = new BroadcastReceiver()
{
@Override
public void onReceive
(Context context, Intent intent
) {
final String action
= intent.
getAction();
// BluetoothAdapter.ACTION_STATE_CHANGED
// Codigo que se ejecutara cuando el Bluetooth cambie su estado.
// Manejaremos los siguientes estados:
// - STATE_OFF: El Bluetooth se desactiva
// - STATE ON: El Bluetooth se activa
if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action))
{
final int estado = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
BluetoothAdapter.ERROR);
switch (estado)
{
// Apagado
case BluetoothAdapter.STATE_OFF:
{
Log.v(TAG, "onReceive: Apagando");
// ((Button)findViewById(R.id.btnBluetooth)).setText(R.string.ActivarBluetooth);
// ((Button)findViewById(R.id.btnBuscarDispositivo)).setEnabled(false);
// ((Button)findViewById(R.id.btnConectarDispositivo)).setEnabled(false);
break;
}
// Encendido
case BluetoothAdapter.STATE_ON:
{
Log.v(TAG, "onReceive: Encendiendo");
// ((Button)findViewById(R.id.btnBluetooth)).setText(R.string.DesactivarBluetooth);
// ((Button)findViewById(R.id.btnBuscarDispositivo)).setEnabled(true);
// ((Button)findViewById(R.id.btnConectarDispositivo)).setEnabled(true);
// Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
// discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
// startActivity(discoverableIntent);
break;
}
case BluetoothAdapter.STATE_DISCONNECTED:
{
Log.v(TAG, "onReceive: Desconectandose");
long[] pattern = { 0, 500,50,500,50,500,50,500};
Vibrator v
= (Vibrator
) getSystemService
(Context.
VIBRATOR_SERVICE); v.vibrate(pattern, -1);
break;
}
default:
break;
} // Fin switch
} // Fin if
} // Fin onReceive
};