當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。