Android 스마트 폰을 사용하여 ibeacon을 감지하려고합니다. 나에게 안드로이드 라이브러리를 제공 한 회사에서 ibeacon 장치를 구입했다. (이 라이브러리는 내가 사용한 코드와 같은 AltBeacon의 안드로이드 비컨 라이브러리와 매우 흡사하다.) 나는이 장치를 감지 볼 수있는 로그 캣에서 전화 응용 프로그램을 실행하면android의 ibeacon 스캔 결과가 스마트 폰에 표시되지 않음
public class IBeaconListAdapter extends BaseAdapter {
private Activity activity;
private List<IBeacon> beacons;
private static LayoutInflater inflater = null;
public IBeaconListAdapter(Activity _activity, List<IBeacon> _beacons) {
this.activity = _activity;
this.beacons = _beacons;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return beacons.size();
}
@Override
public Object getItem(int position) {
return beacons.get(position);
}
@Override
public long getItemId(int position) {
/*IBeacon beacon = beacons.get(position);
if (beacon != null) {
return beacon.hashCode();
}*/
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (convertView == null) {
view = inflater.inflate(R.layout.beacon_list_row, null);
}
TextView majorTextView = (TextView)view.findViewById(R.id.majorValue);
TextView minorTextView = (TextView)view.findViewById(R.id.minorValue);
TextView rssiTextView = (TextView)view.findViewById(R.id.rssiValue);
TextView accuracyTextView = (TextView)view.findViewById(R.id.accuracyValue);
IBeacon beacon = beacons.get(position);
if (beacon != null) {
DecimalFormat df = new DecimalFormat("#.0");
majorTextView.setText(beacon.getMajor());
minorTextView.setText(beacon.getMinor());
rssiTextView.setText(beacon.getRssi() + " dBm");
accuracyTextView.setText(df.format(beacon.getAccuracy()) + " m");
}
return view;
}
}
동안, 다음은 목록을 만들 수있는 두 번째 활동이 년대 MainActivity
public class MainActivity extends Activity implements IBeaconConsumer {
private static final String TAG = "BB-EXAPP";
// iBeacon bluetooth scanning parameters
private static final int FOREGROUND_SCAN_PERIOD = 1000;
private static final int FOREGROUND_BETWEEN_SCAN_PERIOD = 1000;
private static final int BACKGROUND_SCAN_PERIOD = 250;
private static final int BACKGROUND_BETWEEN_SCAN_PERIOD = 2000;
// iBeacon Library Stuff
private static final Region blueupRegion = new Region("BlueUp", "acfd065e-c3c0-11e3-9bbe-1a514932ac01", null, null);
private IBeaconManager iBeaconManager = IBeaconManager.getInstanceForApplication(this);
private Intent iBeaconService;
private boolean isMonitoring = false;
private boolean isRanging = false;
// Android BLE Stuff
private BluetoothAdapter mBluetoothAdapter;
private static final int REQUEST_ENABLE_BT = 1;
// UI Stuff
private List<IBeacon> beacons;
private ListView listView;
private IBeaconListAdapter listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initializes Bluetooth adapter
final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothAdapter = bluetoothManager.getAdapter();
// Ensures Bluetooth is available on the device and it is enabled. If not,
// displays a dialog requesting user permission to enable Bluetooth.
if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
}
// Initializes iBeacon Service
iBeaconService = new Intent(getApplicationContext(), IBeaconService.class);
// Start the iBeacon Service
Log.d(TAG, "Starting service: iBeaconService");
startService(iBeaconService);
// Set desired scan periods
iBeaconManager.setForegroundScanPeriod(FOREGROUND_SCAN_PERIOD);
iBeaconManager.setForegroundBetweenScanPeriod(FOREGROUND_BETWEEN_SCAN_PERIOD);
iBeaconManager.setBackgroundScanPeriod(BACKGROUND_SCAN_PERIOD);
iBeaconManager.setBackgroundBetweenScanPeriod(BACKGROUND_BETWEEN_SCAN_PERIOD);
// Bind the iBeacon Service
iBeaconManager.bind(this);
//
// UI Initialization
//
// Create Empty IBeacons List
beacons = new ArrayList<IBeacon>();
// Create List Adapter
listAdapter = new IBeaconListAdapter(this, beacons);
// Get ListView
listView = (ListView)findViewById(R.id.listView);
// Set ListAdapter
listView.setAdapter(listAdapter);
}
@Override
public void onIBeaconServiceConnect() {
Log.d(TAG, "onIBeaconServiceConnect");
// Set Monitor Notifier
iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
@Override
public void didExitRegion(Region region) {
Log.d(TAG, "didExitRegion: region = " + region.toString());
}
@Override
public void didEnterRegion(Region region) {
Log.d(TAG, "didEnterRegion: region = " + region.toString());
// Set Range Notifier
iBeaconManager.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<IBeacon> iBeacons, Region region) {
// Update UI iBeacons List
beacons = new ArrayList<IBeacon>(iBeacons);
listAdapter.notifyDataSetChanged();
// Log found iBeacons
Log.d(TAG, "didRangeBeaconsInRegion: region = " + region.toString());
if (!iBeacons.isEmpty()) {
int j = 0;
for (IBeacon beacon : iBeacons) {
Log.d(TAG, " [" + j + "] (Major = " + beacon.getMajor() + ", Minor = " + beacon.getMinor() + ", RSSI = " + beacon.getRssi() + ", Accuracy = " + beacon.getAccuracy() + ")");
j++;
}
}
}
});
// Start Ranging
try {
iBeaconManager.startRangingBeaconsInRegion(blueupRegion);
isRanging = true;
Log.d(TAG, "startRangingBeaconsInRegion: region = " + blueupRegion.toString());
} catch (RemoteException e) {
Log.d(TAG, "startRangingBeaconsInRegion [RemoteException]");
e.printStackTrace();
}
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.d(TAG, "didDetermineStateForRegion: state = " + state + ", region = " + region.toString());
}
});
// Start Monitoring
try {
iBeaconManager.startMonitoringBeaconsInRegion(blueupRegion);
isMonitoring = true;
Log.d(TAG, "startMonitoringBeaconsInRegion: region = " + blueupRegion.toString());
} catch (RemoteException e) {
Log.d(TAG, "startMonitoringBeaconsInRegion [RemoteException]");
e.printStackTrace();
}
}
@Override
public void onResume() {
Log.d(TAG, "onResume");
super.onResume();
if (iBeaconManager.isBound(this)) {
iBeaconManager.setBackgroundMode(this, false);
Log.d(TAG, "iBeaconManager.setBackgroundMode = false");
}
}
@Override
public void onStop() {
Log.d(TAG, "onStop");
if (iBeaconManager.isBound(this)) {
iBeaconManager.setBackgroundMode(this, true);
Log.d(TAG, "iBeaconManager.setBackgroundMode = true");
}
super.onStop();
}
@Override
public void onDestroy() {
Log.d(TAG, "onDestroy");
if (isRanging) {
try {
iBeaconManager.stopRangingBeaconsInRegion(blueupRegion);
Log.d(TAG, "stopRangingBeaconsInRegion: region = " + blueupRegion.toString());
} catch (RemoteException e) {
Log.d(TAG, "stopRangingBeaconsInRegion [RemoteException]");
e.printStackTrace();
}
}
if (isMonitoring) {
try {
iBeaconManager.stopMonitoringBeaconsInRegion(blueupRegion);
Log.d(TAG, "stopMonitoringBeaconsInRegion: region = " + blueupRegion.toString());
} catch (RemoteException e) {
Log.d(TAG, "stopMonitoringBeaconsInRegion [RemoteException]");
e.printStackTrace();
}
}
if (iBeaconManager.isBound(this)) {
Log.d(TAG, "Unbinding iBeaconManager");
iBeaconManager.unBind(this);
}
Log.d(TAG, "Stopping service: iBeaconService");
stopService(iBeaconService);
super.onDestroy();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
입니다 전화에서 나는 아무것도 볼 수없는 빈 페이지! LogCat에서 일단 onIBeaconServiceConnect가 호출되면 app이 startMonitoringBeaconsInRegion으로 점프하고 didRangeBeaconsInRegion 및 코드를 포함하는 didEnterRegion 메서드를 호출하지 않는다는 것을 알았습니다. 내 질문과 유사한 질문에 대한 다른 답변을 찾을 수 없으며 실제로 내 실수가 어디인지 알 수 없습니다.
"LogCat에서 장치를 감지 한 것을 볼 수 있습니까?"라는 것은 무엇을 의미합니까? LogCat에서보고있는 것을 게시하여 생각하게 할 수 있습니까? – davidgyoung