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


Java BluetoothDevice.DEVICE_TYPE_LE属性代码示例

本文整理汇总了Java中android.bluetooth.BluetoothDevice.DEVICE_TYPE_LE属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothDevice.DEVICE_TYPE_LE属性的具体用法?Java BluetoothDevice.DEVICE_TYPE_LE怎么用?Java BluetoothDevice.DEVICE_TYPE_LE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.bluetooth.BluetoothDevice的用法示例。


在下文中一共展示了BluetoothDevice.DEVICE_TYPE_LE属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	Fabric.with(this, new Crashlytics());
	setContentView(R.layout.activity_main);

	ActionBar bar = getSupportActionBar();
	if(bar != null) {
		bar.setDisplayHomeAsUpEnabled(true);
	}

	headingIndicator = findViewById(R.id.heading_indicator);

	final Intent intent = getIntent();

	if(intent.hasExtra(HomeActivity.EXTRA_DEMO)) {
		setTitle("Demo");

		bluetoothConnection = new BluetoothDemoConnection(this, null, this);
	} else {
		String deviceAddress = intent
				.getStringExtra(DeviceListActivity.EXTRAS_DEVICE_ADDRESS);

		// Set activity title to the name of the connected device
		setTitle(intent.getStringExtra(DeviceListActivity.EXTRAS_DEVICE_NAME));

		int deviceType = intent.getIntExtra(DeviceListActivity.EXTRAS_DEVICE_TYPE,
											BluetoothDevice.DEVICE_TYPE_UNKNOWN);

		if (deviceType == BluetoothDevice.DEVICE_TYPE_LE) {
			bluetoothConnection = new BluetoothLeConnection(this, deviceAddress, this);
		} else if (deviceType == BluetoothDevice.DEVICE_TYPE_CLASSIC) {
			bluetoothConnection = new BluetoothClassicConnection(this, deviceAddress, this);
		} else {
			finish();
		}
	}

	getLifecycle().addObserver(bluetoothConnection);

	fragmentManager = getSupportFragmentManager();

	// Display the joystick fragment
	setCurrentFragment(FRAGMENT_JOYSTICK);

	progress = new ProgressDialog(this);
	progress.setTitle("Connecting...");
	progress.setIndeterminate(true);
	progress.show();
}
 
开发者ID:Make-A-Pede,项目名称:Make-A-Pede-Android-App,代码行数:50,代码来源:ControllerActivity.java

示例2: connect

@Override
public synchronized void connect(String address) {
 if (mBluetoothAdapter == null || address == null) {
  NLog.w("BluetoothAdapter not initialized or unspecified address.");
  this.responseMsg(new PenMsg(PenMsgType.PEN_CONNECTION_FAILURE));
  return;
 }

 if (penAddress != null)
 {
  if (this.penStatus == CONN_STATUS_AUTHORIZED)
  {
   responseMsg(new PenMsg(PenMsgType.PEN_ALREADY_CONNECTED));
   return;
  }
  else if (this.penStatus != CONN_STATUS_IDLE)
  {
   return;
  }
 }

    final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
    if (device == null) {
        NLog.w("Device not found.  Unable to connect.");
        this.responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE ) );
        return;
    }

    if ( device.getType() != BluetoothDevice.DEVICE_TYPE_LE )
    {
        NLog.w("MacAddress is not Bluetooth LE Type");
        this.responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE ) );
        return;
    }

 if ( this.penStatus != CONN_STATUS_IDLE ) {
  responseMsg(new PenMsg(PenMsgType.PEN_CONNECTION_FAILURE));
  return;
 }

 this.penAddress = address;
    onConnectionTry();
 responseMsg(new PenMsg(PenMsgType.PEN_CONNECTION_TRY));

    this.penBtName = device.getName();

    this.watchDog = new Timer();
    this.watchDogTask = new TimerTask() {
        @Override
        public void run() {
            watchDogAlreadyCalled = true;
            NLog.d("Run WatchDot : connect failed");
            responseMsg( new PenMsg( PenMsgType.PEN_CONNECTION_FAILURE) );
            onDisconnected();
            close();
        }
    };

    this.watchDogAlreadyCalled = false;
    this.mBluetoothGatt = device.connectGatt(context, false, mBluetoothGattCallback);
 try {
  // schedule이 시작전에 connectGatt가 불려서 Cancel이 되어버리는 경우에 대한 exception처리
  // 커넥션 이후엔 여기에 문제가 생겨도 지장없음.
  this.watchDog.schedule(watchDogTask, 3000);  // 3초
 }
 catch (Exception e)
 {
  e.printStackTrace();
 }
    NLog.d("Trying to create a new connection.");
}
 
开发者ID:NeoSmartpen,项目名称:AndroidSDK2.0,代码行数:71,代码来源:BTLEAdt.java

示例3: onLeScan

@Override
public void onLeScan(final BluetoothDevice device, int i, byte[] bytes) {
    if (device.getType() == BluetoothDevice.DEVICE_TYPE_LE) {
        onFind(device);
    }
}
 
开发者ID:e-regular-games,项目名称:arduator,代码行数:6,代码来源:ArduinoCommManagerBle.java


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