当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothAdapter.getRemoteDevice方法代码示例

本文整理汇总了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;
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:21,代码来源:BleProfileService.java

示例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;
}
 
开发者ID:runtimeco,项目名称:Android-DFU-App,代码行数:26,代码来源:BleProfileService.java

示例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 + ".");

}
 
开发者ID:aidaferreira,项目名称:synesthesiavision,代码行数:35,代码来源:BluetoothThread.java

示例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);
}
 
开发者ID:ErikHellman,项目名称:AndroidBleWrapper,代码行数:7,代码来源:BleWrapper.java

示例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();
}
 
开发者ID:Elbehiry,项目名称:Pc-Control,代码行数:43,代码来源:RemoteItConnectionBluetooth.java


注:本文中的android.bluetooth.BluetoothAdapter.getRemoteDevice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。