我正在尝试在我的应用程序中实现信标检测,并且我正在使用altBeacon库,我已经采用了在库的站点中显示的示例,但是ti似乎无法正常工作。 这是代码:
public class BeaconActivity extends BaseActivity implements BeaconConsumer,RangeNotifier {
private BeaconManager beaconManager;
private TextView text;
@Override
protected void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
setContentView(R.layout.beacon_layout);
text=(TextView) findViewById(R.id.rangingText);
}
@Override
protected void onDestroy(){
super.onDestroy();
beaconManager.unbind(this);
}
@Override
public void onBeaconServiceConnect() {
ArrayList<Identifier> identifiers=new ArrayList<>();
identifiers.add(null);
Region region=new Region("all-beacons-region",identifiers);
try{
beaconManager.startRangingBeaconsInRegion(region);
} catch (RemoteException e) {
e.printStackTrace();
}
beaconManager.setRangeNotifier(this);
}
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
Log.d("PROVA", "size: "+beacons.size());
for (Beacon beacon: beacons){
Identifier nameId=beacon.getId1();
Identifier instanceID=beacon.getId2();
Log.d("BEACON FOUND ", nameId + instanceID.toString() );
logToDisplay("BEACON FOUND");
}
}
@Override
public void onBackPressed(){
startActivity(new Intent(BeaconActivity.this, Main_Activity_login.class));
finish();
}
public void logToDisplay(final String string){
runOnUiThread(new Runnable() {
@Override
public void run() {
text.append(string + "\n");
}
});
}
@Override
public void onPause(){
super.onPause();
beaconManager.unbind(this);
}
@Override
public void onResume(){
super.onResume();
beaconManager=BeaconManager.getInstanceForApplication(getApplicationContext());
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("s:0-1=feaa,m:2-2=00,p:3-3:-41,i:4-13,i:14-19"));
beaconManager.bind(this);
}
} 这里结束的是StackRace:
01-22 15:58:43.147 786-907/? I/ActivityManager: Displayed Component not be shown by security: +140ms
01-22 15:58:43.157 1692-1692/? D/SamsungIME: onStartInput: No inputType, No imeOption, isInputViewShown = false, isExtractViewShown = false, isShowInputRequested = false, isConfigChanged = false
01-22 15:58:43.167 786-849/? D/SensorService: [SO] -0.194 0.195 9.692
01-22 15:58:43.177 9414-9424/? D/BtGatt.GattService: registerClient() - UUID=7a37c868-1fbf-4b1d-a559-acf8bda372a3
01-22 15:58:43.217 9414-9576/? D/BtGatt.GattService: onClientRegistered() - UUID=7a37c868-1fbf-4b1d-a559-acf8bda372a3, clientIf=6
01-22 15:58:43.217 8878-8896/? D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=6
01-22 15:58:43.217 9414-9680/? D/BtGatt.GattService: start scan with filters
01-22 15:58:43.227 9414-9680/? D/BtGatt.GattService: 1. app : com.android.bluetooth 2. Action : LESC 3. Callng app : com.example.stage.drawlayoutproject 4. Count : 437
01-22 15:58:43.227 9414-9581/? D/BtGatt.ScanManager: handling starting scan
01-22 15:58:43.227 9414-9581/? D/BtGatt.ScanManager: isFilteringSupported
01-22 15:58:43.227 9414-9581/? D/BluetoothAdapter: setting StandAloneBleMode
01-22 15:58:43.227 9414-9581/? D/BtGatt.ScanManager: isFilteringSupported
01-22 15:58:43.227 9414-9581/? D/BluetoothAdapter: setting StandAloneBleMode
01-22 15:58:43.227 9414-9581/? D/BtGatt.ScanManager: isFilteringSupported
01-22 15:58:43.227 9414-9581/? D/BluetoothAdapter: setting StandAloneBleMode
01-22 15:58:43.227 9414-9581/? D/BtGatt.ScanManager: configureRegularScanParams() - queue=1
01-22 15:58:43.227 9414-9581/? D/BtGatt.ScanManager: configureRegularScanParams() - ScanSetting Scan mode=2 mLastConfiguredScanSetting=-2147483648
01-22 15:58:43.227 9414-9581/? I/BtGatt.ScanManager: :scan window =5000 Scan interval = 5000
01-22 15:58:43.237 786-1207/? D/WindowManager: beginLayoutLw mStatusBar.isVisibleLw() = true, statusBarTransient=false, displayId=0
01-22 15:58:43.257 8878-9403/? D/OpenGLRenderer: endAllStagingAnimators on 0xb495d580 (RippleDrawable) with handle 0xa0cc53a0
01-22 15:58:43.257 786-1433/? D/WindowManager: beginLayoutLw mStatusBar.isVisibleLw() = true, statusBarTransient=false, displayId=0
01-22 15:58:43.267 8878-8878/? I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@12c14703 time:52084489
01-22 15:58:43.427 786-907/? D/CustomFrequencyManagerService: releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT frequency : 1190400 uid : 1000 pid : 786 tag : ACTIVITY_RESUME_BOOSTER@4
01-22 15:58:43.427 786-907/? W/ActivityManager: mDVFSHelper.release()
01-22 15:58:43.427 786-907/? I/Timeline: Timeline: Activity_windows_visible id: ActivityRecord{33c30f9e u0 com.example.stage.drawlayoutproject/.BeaconActivity t237} time:52084641
01-22 15:58:43.427 234-932/? I/SurfaceFlinger: id=4040 Removed Nain_Activi (3/9)
01-22 15:58:43.427 786-851/? D/CustomFrequencyManagerService: acquireDVFSLockLocked : type : DVFS_MIN_LIMIT frequency : 1190400 uid : 1000 pid : 786 pkgName : ACTIVITY_RESUME_BOOSTER@8
01-22 15:58:43.427 234-341/? I/SurfaceFlinger: id=4040 Removed Nain_Activi (-2/9)
01-22 15:58:43.427 234-18292/? I/SurfaceFlinger: id=4042 Removed Nain_Activi (4/8)
01-22 15:58:43.427 234-932/? I/SurfaceFlinger: id=4042 Removed Nain_Activi (-2/8)
01-22 15:58:43.427 786-907/? D/WindowManager: beginLayoutLw mStatusBar.isVisibleLw() = true, statusBarTransient=false, displayId=0
01-22 15:58:43.427 786-1920/? D/WindowManager: beginLayoutLw mStatusBar.isVisibleLw() = true, statusBarTransient=false, displayId=0
01-22 15:58:43.437 786-1418/? D/WindowManager: beginLayoutLw mStatusBar.isVisibleLw() = true, statusBarTransient=false, displayId=0
01-22 15:58:43.437 234-234/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
01-22 15:58:43.437 234-234/? W/SurfaceFlinger: couldn't log to binary event log: overflow.
01-22 15:58:43.477 786-907/? D/WindowManager: beginLayoutLw mStatusBar.isVisibleLw() = true, statusBarTransient=false, displayId=0
01-22 15:58:43.547 1159-1159/? D/StatusBar.NetworkController: refreshViews connected={ wifi } level=0 combinedSignalIconId=0x7f020594/com.android.systemui:drawable/stat_sys_wifi_signal_3 mobileLabel= wifiLabel="ETIWIFI2015" emergencyOnly=false combinedLabel= mAirplaneMode=true mDataActivity=0 mPhoneSignalIconId=0x0/(null) mQSPhoneSignalIconId=0x0/(null) mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x0/(null) mDataTypeIconId=0x0/(null) mQSDataTypeIconId=0x0/(null) mNoSimIconId=0x0/(null) mWifiIconId=0x7f020594/com.android.systemui:drawable/stat_sys_wifi_signal_3 mQSWifiIconId=0x7f02014f/com.android.systemui:drawable/ic_qs_wifi_3 mWifiActivityIconId=0x7f02055d/com.android.systemui:drawable/stat_sys_signal_inout mBluetoothTetherIconId=0x7f020572/com.android.systemui:drawable/stat_sys_tether_bluetooth
01-22 15:58:43.547 1159-1159/? D/STATUSBAR-WifiTile: onWifiSignalChanged enabled=true enabledDesc:"ETIWIFI2015"
01-22 15:58:43.547 1159-1159/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
01-22 15:58:43.547 1159-1159/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
01-22 15:58:43.547 1159-1159/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
01-22 15:58:43.547 1159-1159/? D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
01-22 15:58:43.627 9414-9576/? E/bt-btif: property type:241, len:0 is invalid
01-22 15:58:43.627 9414-9576/? E/BluetoothRemoteDevices: devicePropertyChangedCallback: bdDevice: C0:4F:78:38:0B:45, value is empty for type: 241
01-22 15:58:43.627 9414-9576/? D/BluetoothUtils: getBtEnabledContainers(): btContainers = []
01-22 15:58:43.627 9414-9576/? D/BluetoothUtils: getBtEnabledContainers(): btContainers = []
01-22 15:58:43.627 9414-9576/? D/ScanRecord: parseFromBytes
01-22 15:58:43.627 9414-18085/? D/BtGatt.ContextMap: sendClientScanResult for app id 6
01-22 15:58:43.637 8878-9462/? D/ScanRecord: parseFromBytes
01-22 15:58:43.637 8878-9462/? D/BluetoothLeScanner: onScanResult() - ScanResult{mDevice=C0:4F:78:38:0B:45, mScanRecord=ScanRecord [mAdvertiseFlags=6, mServiceUuids=[adabfb00-6e7d-4601-bda2-bffaa68956ba], mManufacturerSpecificData={}, mServiceData={0000180a-0000-1000-8000-00805f9b34fb=[8, 6, -95, 52, 0, 0]}, mTxPowerLevel=-6, mDeviceName=Charge], mRssi=-88, mTimestampNanos=167613539638624}
01-22 15:58:44.097 3631-3631/? E/wpa_supplicant: IAPP SNAP_HDR Mismatch
01-22 15:58:44.097 3631-3631/? E/wpa_supplicant: IAPP SNAP_HDR Mismatch
01-22 15:58:44.097 3631-3631/? E/wpa_supplicant: IAPP SNAP_HDR Mismatch
01-22 15:58:44.327 786-1418/? D/ActivityManager: retrieveServiceLocked(): component = com.example.stage.drawlayoutproject/org.altbeacon.beacon.BeaconIntentProcessor; callingUser = 0; userId(target) = 0
01-22 15:58:44.337 9414-9424/? D/BtGatt.GattService: stopScan() - queue size =1
01-22 15:58:44.337 9414-9680/? D/BtGatt.GattService: unregisterClient() - clientIf=6
01-22 15:58:44.337 9414-9581/? D/BtGatt.ScanManager: stop scan
01-22 15:58:44.337 9414-9581/? D/BtGatt.ScanManager: configureRegularScanParams() - queue=0
01-22 15:58:44.337 9414-9581/? D/BtGatt.ScanManager: configureRegularScanParams() - ScanSetting Scan mode=-2147483648 mLastConfiguredScanSetting=2
01-22 15:58:44.337 9414-9581/? D/BtGatt.ScanManager: configureRegularScanParams() - queue emtpy, scan stopped
01-22 15:58:44.337 9414-9578/? D/BtGatt.GattService: registerClient() - UUID=2298e6e2-c52f-48ca-bb29-f90aeb34169a
01-22 15:58:44.377 9414-9576/? D/BtGatt.GattService: onClientRegistered() - UUID=2298e6e2-c52f-48ca-bb29-f90aeb34169a, clientIf=6
01-22 15:58:44.377 8878-8894/? D/BluetoothLeScanner: onClientRegistered() - status=0 clientIf=6
实际上,似乎在stackRace中检测到信标,但应用程序无法显示它。 提前谢谢。
答案 0 :(得分:0)
您可以从GitHub中引用beacon library。
答案 1 :(得分:0)
一些提示:
确保您尝试检测的信标类型不需要将自定义BeaconParser
添加到库中。默认情况下,库只会检测开源AltBeacons。您需要添加一行代码才能使其检测其他信标类型。谷歌搜索&#34; BeaconParser&#34;和你的灯塔类型,以了解如何。
确保Locate等现成的应用会检测到您的信标。
如果上述方法均无法解决问题,请尝试设置beaconManager.setDebug(true);
并收集新的LogCat摘录以添加到您的问题中。