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