0
내가
서비스 클래스를 확장하는 클래스에 라이브러리 albeacon
내 표지를 스캔하고
public class BeaconActivity extends Service implements BeaconConsumer{}
내 질문은 다음과 같습니다
1 곳/정지 시작 이 서비스? 나는 응용 프로그램 스캔을
startService(new Intent(getApplicationContext(), BeaconActivity.class));
stopService(new Intent(getApplicationContext(), BeaconActivity.class));
2 내가/시작할 수있는 모든 시간을 원하는 경우 일부 버튼를 사용하여이 서비스를 중지?
public class BeaconActivity extends Service implements BeaconConsumer {
BeaconManager beaconManager;
private static final String UUID1 = "B9407F30-F5F8-466E-AFF9-25556B57FE6D";
private static final String Major1 = "14152";
public static boolean isInBeaconRegion =false;
int value, id,distance;
String beaconMinor;
public void onCreate() {
super.onCreate();
beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().clear();
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
// 5 seconds
beaconManager.setBackgroundBetweenScanPeriod(8000l);
beaconManager.setForegroundBetweenScanPeriod(8000l);
beaconManager.bind(this); }
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// -- continue running until it is stopped --
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY; }
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show(); }
@Override
public void onBeaconServiceConnect() {
beaconManager.addRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> collection, Region region) {
for (int i = 0; i < collection.size(); i++) {
final Beacon beacon = collection.iterator().next();
// -- Get Beacon UUID --
String UUID2 = beacon.getId1().toString().toUpperCase();
// -- Get Beacon Minor --
String Major2 = beacon.getId2().toString();
if (UUID2.equals(UUID1) && Major2.equals(Major1)) {
// -- Get Beacon Minor --
beaconMinor = beacon.getId3().toString();
//Check the minor
} } }
});
try {
beaconManager.startRangingBeaconsInRegion(new Region("B9407F30-F5F8-466E-AFF9-25556B57FE6D", null, null, null));
} catch (RemoteException e) {
} }
입니다. 그러나 사용자가 (스캔 시작)을 누르고 그 주변에 비컨이 없으면 어떻게 될까요? 어디에서 토스트 경고를 할 수 있습니까? - 내 수업이 붙어 있어요. – Abrar