2017-05-20 6 views
0

안녕에 Bluez를 사용하여 만든 명령안드로이드 찾기 비콘 내가 다음 비콘이 만든 라즈베리 파이 3.</p> <p>에서 내가 Bluez 5.23를 사용하여 만든 Eddystone UID 비콘에 안드로이드 응용 프로그램을 연결하려고 사용하고 리눅스

sudo hciconfig hci0 up 
sudo hciconfig hci0 leadv 3 
sudo hcitool -i hci0 cmd 0x08 0x0008 1F 02 01 06 03 03 AA FE 17 16 AA FE 00 E7 01 02 03 04 05 06 07 08 09 0A 01 02 03 04 05 06 00 00 

이 신호는 분명히 내가 Beacon Toy 같은 일부 스토어 앱을 사용하여 안드로이드 장치에서 볼 수있는 원인이 제대로 작동합니다.

public class MainActivity extends AppCompatActivity implements BeaconConsumer, MonitorNotifier { 
... 
@Override 
public void onResume() { 
    super.onResume(); 
    beaconManager = BeaconManager.getInstanceForApplication(this.getApplicationContext()); 
    beaconManager.getBeaconParsers().add(new BeaconParser(). 
      setBeaconLayout(BeaconParser.EDDYSTONE_UID_LAYOUT)); 
    beaconManager.bind(this); 
} 

@Override 
public void onBeaconServiceConnect() { 
    Region region = new Region("my-beacon-region", null, null, null); 
    beaconManager.addMonitorNotifier(this); 
    try { 
     beaconManager.startMonitoringBeaconsInRegion(region); 
    } catch (RemoteException e) { 
     e.printStackTrace(); 
    } 
} 

public void didEnterRegion(Region region) { 
    Log.d(TAG, "I detected a beacon in the region with namespace id " + region.getId1() + 
      " and instance id: " + region.getId2()); 
} 
} 

누구나 일이 될 수 있습니다 알고 :

나는 비콘을 발견하기 위해 주요 활동 안에 다음 코드를 사용하고? 메서드 didEnterRegion이 호출되지 않습니다. 또한 클래스 내에 'didDetermineStateForRegion'메서드를 넣었지만 항상 지역 변수가 아니라는 것을 의미하는 상태 매개 변수로 OUTSIDE을받습니다.

답변

1

응용 프로그램에 대한 Bluetooth 및 위치 권한을 요청하지 않았거나 승인하지 않은 것 같습니다. 보세요 : https://altbeacon.github.io/android-beacon-library/requesting_permission.html.

당신이 확실하게 이미 다음 몇 가지 질문에 올바른 사용 권한이있는 경우 :
는 비컨 장난감 응용 프로그램에 의해 Eddystone UID로 인식 비콘인가?
onBeaconServiceConnect가 호출 되었습니까?

작은 힌트 : onResume 대신 onCreate 메서드에서 BeaconManager를 초기화하는 것이 좋습니다. 지금 앱을 다시 시작할 때마다 새 파서를 추가하고 있습니다. 사실 onCreate가 여러 번 호출 될 수 있으므로 응용 프로그램 객체에서 실제로이 작업을 수행하고 있습니다.

+0

블루투스 사용 권한이 부여되는지 확인하는 것이 중요합니다. 그렇지 않으면 앱이 감지되지 않고 항상 밖에있을 것입니다. – davidgyoung