public void onReceive(Context context, Intent intent) { String action = intent.getAction(); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (BluetoothDevice.ACTION_FOUND.equals(action)) { Toast.makeText( getApplicationContext(), "Device found" + device.getName(), Toast.LENGTH_SHORT) .show(); // Device found if (device.getName().equals("SM-T325")) { visits++; ((TextView) findViewById(R.id.textView)) .setText("Number of visits this month: " + MainActivity.visits + " times"); } } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { Toast.makeText(getApplicationContext(), "Action connected", Toast.LENGTH_SHORT) .show(); // Device is now connected } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { Toast.makeText(getApplicationContext(), "Discovery finished", Toast.LENGTH_SHORT) .show(); // Done searching } else if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) { Toast.makeText(getApplicationContext(), "Disconnect Requested", Toast.LENGTH_SHORT) .show(); // Device is about to disconnect } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { Toast.makeText(getApplicationContext(), "Disconnected", Toast.LENGTH_SHORT) .show(); // Device has disconnected } }
private void onReceiveActionAclConnection(Intent intent) { Log.d(TAG, "onReceiveActionAclConnection action: " + intent.getAction()); String action = intent.getAction(); if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { showNotification(AUDIO_PATH_A2DP); } else { showNotification(getCurrentAudioPathOtherThanA2dp()); } }
@Override public void onReceive(Context context, Intent intent) { if (intent == null) return; String action = intent.getAction(); if (TextUtils.isEmpty(action)) return; if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) { onReceiveActionAudioBecomingNoisy(intent); } else if (Intent.ACTION_HEADSET_PLUG.equals(action)) { onReceiveActionHeadsetPlug(intent); } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action) || BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { onReceiveActionAclConnection(intent); } }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); if (BluetoothDevice.ACTION_FOUND.equals(action)) { // ... //Device found } else if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) { // Device is now connected PrintHelper.SetIsConnected(true); AppGlobals.printerTestDialogFragment.SetPrinterStatus(); } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) { // Done searching } else if (BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED.equals(action)) { // Device is about to disconnect } else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action)) { // Device has disconnected PrintHelper.SetIsConnected(false); AppGlobals.printerTestDialogFragment.SetPrinterStatus(); } }