2017-09-28 3 views
1

안녕하십니까, BLE 앱에서 개발 중이며 GATT 연결을위한 활동을 작성했습니다. 때로는 시스템이 서비스와 특성 및 기타 시간을 인식하기 때문에 문제가 발생합니다. 여기 낮은 에너지의 블루투스 서비스가 항상 발견되지 않습니다.

는 내 코드의 일부 :

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_gatt); 

    peripheralTextView = (TextView) findViewById(R.id.PeripheralTextView); 
    peripheralTextView.setMovementMethod(new ScrollingMovementMethod()); 

    scanServiceButton = (Button) findViewById(R.id.scan_service); 
    scanServiceButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      mBluetoothGatt.discoverServices(); 
     } 
    }); 

    //get the Bluetooth device which comes from mainActivity 
    BluetoothDevice bluetoothDevice = getIntent().getExtras().getParcelable("selectedDevice"); 
    String test = bluetoothDevice.getAddress(); 
    Toast toast = Toast.makeText(this, "Verbunden mit " + test, Toast.LENGTH_LONG); 
    toast.show(); 

    Log.d("GattActivity", "connectGatt()"); 
    mBluetoothGatt = bluetoothDevice.connectGatt(this, false, mGattCallback); 
} 

그리고 난 그것을하지 않는 모든 값하지만 여러 번 어떤으로 서비스를받을 경우 때때로 이것이 나의 onServiceDiscovered입니다 : 내가 봤

 @Override 
    public void onServicesDiscovered(BluetoothGatt gatt, int status) { 
     //new Services discovered 
     if(status == BluetoothGatt.GATT_SUCCESS){ 
      broadcastUpdate(ACTION_GATT_SERVICES_DISCOVERED); 
      displayGattServices(mBluetoothGatt.getServices()); 
     }else{ 
      Log.d("GattActivity", "onServicesDiscovered received: " + status); 
     } 
    } 

많이 그리고 나는 그것이 Google의 견본과 매우 유사하다고 생각하지만 때로는 왜 보여줄 지, 때로는 알지 못합니다.

아마 누군가가 지금이 바로 희망 나는 해결책을 가지고 나

+0

테스트 한 장치를 아는 것이 중요 할 수 있습니다. 나는 Samsung s5 mini와 Google Nexus 5를 사용했으며 Google의 Advtertisement Sample을 통해 OnePlus 3t를 통해 광고를 보냅니다. – Fab

답변

0

도움을 줄 수 있습니다.

내가 한 첫 번째 일은 우리가 거친 위치에 액세스 할 수 있도록하는 것이 었습니다.

if(this.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)!= PackageManager.PERMISSION_GRANTED){...} 

둘째 나는 그러나 경우 (약 50 시간이 지금 작동 희망 테스트) 내가 그것을 매번 작동이 두 가지를 한 후 onConnectionStateChange에서 discoverServices()()

@Override 
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {.... mBluetoothGatt.discoverServices()...;} 

를 사용하는 것을 잊었다 유익한 해결책은 나에게 자유롭게 대답 해주세요.