本文整理汇总了Java中android.bluetooth.BluetoothAdapter.getRemoteDevice方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothAdapter.getRemoteDevice方法的具体用法?Java BluetoothAdapter.getRemoteDevice怎么用?Java BluetoothAdapter.getRemoteDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothAdapter
的用法示例。
在下文中一共展示了BluetoothAdapter.getRemoteDevice方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onStartCommand
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");
mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
// notify user about changing the state to CONNECTING
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
final BluetoothAdapter adapter = bluetoothManager.getAdapter();
final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
mDeviceName = device.getName();
mBleManager.connect(device);
return START_REDELIVER_INTENT;
}
示例2: onStartCommand
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
@Override
public int onStartCommand(final Intent intent, final int flags, final int startId) {
if (intent == null || !intent.hasExtra(EXTRA_DEVICE_ADDRESS))
throw new UnsupportedOperationException("No device address at EXTRA_DEVICE_ADDRESS key");
final Uri logUri = intent.getParcelableExtra(EXTRA_LOG_URI);
mLogSession = Logger.openSession(getApplicationContext(), logUri);
mDeviceAddress = intent.getStringExtra(EXTRA_DEVICE_ADDRESS);
Logger.i(mLogSession, "Service started");
// notify user about changing the state to CONNECTING
final Intent broadcast = new Intent(BROADCAST_CONNECTION_STATE);
broadcast.putExtra(EXTRA_CONNECTION_STATE, STATE_CONNECTING);
LocalBroadcastManager.getInstance(BleProfileService.this).sendBroadcast(broadcast);
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
final BluetoothAdapter adapter = bluetoothManager.getAdapter();
final BluetoothDevice device = adapter.getRemoteDevice(mDeviceAddress);
mDeviceName = device.getName();
onServiceStarted();
mBleManager.connect(device);
return START_REDELIVER_INTENT;
}
示例3: connect
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
/**
* Connect to a remote Bluetooth socket, or throw an exception if it fails.
*/
private void connect() throws Exception {
Log.i(TAG, "Attempting connection to " + address + "...");
sendToReadHandler("CONNECTING");
// Get this device's Bluetooth adapter
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if ((adapter == null) || (!adapter.isEnabled())) {
throw new Exception("Bluetooth adapter not found or not enabled!");
}
// Find the remote device
BluetoothDevice remoteDevice = adapter.getRemoteDevice(address);
// Create a socket with the remote device using this protocol
socket = remoteDevice.createRfcommSocketToServiceRecord(uuid);
Log.i(TAG, "Socket Created.");
// Make sure Bluetooth adapter is not in discovery mode
adapter.cancelDiscovery();
// Connect to the socket
socket.connect();
// Get input and output streams from the socket
outStream = socket.getOutputStream();
inStream = socket.getInputStream();
Log.i(TAG, "Connected successfully to " + address + ".");
}
示例4: getBluetoothDevice
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
private BluetoothDevice getBluetoothDevice(Context context, String deviceAddress) {
BluetoothManager bluetoothManager = (BluetoothManager) context
.getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
return bluetoothAdapter.getRemoteDevice(deviceAddress);
}
示例5: create
import android.bluetooth.BluetoothAdapter; //导入方法依赖的package包/类
public static RemoteItConnectionBluetooth create(ActionControl application, Context mContext, String address) throws IOException
{
Looper.prepare();
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
if (adapter != null)
{
if (adapter.isEnabled())
{
try
{
BluetoothDevice device = adapter.getRemoteDevice(address);
if (device != null)
{
BluetoothSocket socket = device.createRfcommSocketToServiceRecord(UUID.fromString(RemoteItConnection.BLUETOOTH_UUID));
socket.connect();
RemoteItConnectionBluetooth connection = new RemoteItConnectionBluetooth(socket);
return connection;
}
}
catch (IllegalArgumentException e)
{
throw new IOException();
}
}
else
{
if (application.requestEnableBluetooth())
{
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
}
}
throw new IOException();
}