Foros del Web » Programando para Internet » Android »

Sonido al desconectar bluettoth

Estas en el tema de Sonido al desconectar bluettoth en el foro de Android en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 19/05/2014, 08:14
Avatar de edwD  
Fecha de Ingreso: agosto-2013
Mensajes: 18
Antigüedad: 10 años, 8 meses
Puntos: 0
Pregunta Sonido al desconectar bluettoth

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 original
  1. private final BroadcastReceiver bReceiver = new BroadcastReceiver()
  2.         {
  3.             @Override
  4.             public void onReceive(Context context, Intent intent)
  5.             {
  6.                 final String action = intent.getAction();
  7.  
  8.                 // BluetoothAdapter.ACTION_STATE_CHANGED
  9.                 // Codigo que se ejecutara cuando el Bluetooth cambie su estado.
  10.                 // Manejaremos los siguientes estados:
  11.                 //      - STATE_OFF: El Bluetooth se desactiva
  12.                 //      - STATE ON: El Bluetooth se activa
  13.                 if (BluetoothAdapter.ACTION_STATE_CHANGED.equals(action))
  14.                 {
  15.                     final int estado = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
  16.                                                          BluetoothAdapter.ERROR);
  17.                     switch (estado)
  18.                     {
  19.                         // Apagado
  20.                         case BluetoothAdapter.STATE_OFF:
  21.                         {
  22.                             Log.v(TAG, "onReceive: Apagando");
  23.                         //  ((Button)findViewById(R.id.btnBluetooth)).setText(R.string.ActivarBluetooth);
  24.                         //  ((Button)findViewById(R.id.btnBuscarDispositivo)).setEnabled(false);
  25.                         //  ((Button)findViewById(R.id.btnConectarDispositivo)).setEnabled(false);
  26.                             break;
  27.                         }
  28.                        
  29.                         // Encendido
  30.                         case BluetoothAdapter.STATE_ON:
  31.                         {
  32.                             Log.v(TAG, "onReceive: Encendiendo");
  33.                         //  ((Button)findViewById(R.id.btnBluetooth)).setText(R.string.DesactivarBluetooth);
  34.                         //  ((Button)findViewById(R.id.btnBuscarDispositivo)).setEnabled(true);
  35.                         //  ((Button)findViewById(R.id.btnConectarDispositivo)).setEnabled(true);
  36.                            
  37.                         //  Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
  38.                         //  discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 120);
  39.                         //  startActivity(discoverableIntent);
  40.                            
  41.                             break;
  42.                         }
  43.                        
  44.                         case BluetoothAdapter.STATE_DISCONNECTED:
  45.                         {
  46.                             Log.v(TAG, "onReceive: Desconectandose");
  47.                            
  48.                             long[] pattern = { 0, 500,50,500,50,500,50,500};
  49.                             Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
  50.                             v.vibrate(pattern, -1);
  51.                            
  52.                             break;
  53.                         }
  54.                            
  55.                            
  56.                            
  57.                         default:
  58.                             break;
  59.                     } // Fin switch
  60.                    
  61.                 } // Fin if
  62.                
  63.        
  64.              
  65.                
  66.             } // Fin onReceive
  67.  
  68.        
  69.         };

Etiquetas: desconectar
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:26.