android ibeacon搜索,GitHub - inthepocket/ibeacon-scanner-android: Android library to scan for iBeacons...

iBeacon scanner android

68747470733a2f2f7472617669732d63692e6f72672f696e746865706f636b65742f69626561636f6e2d7363616e6e65722d616e64726f69642e7376673f6272616e63683d6d6173746572

687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c6174

Android library to scan for iBeacons.

Download the library

You can download the library via Gradle from the jCenter repository:

repositories {

jcenter()

}

By adding the dependency in your module level build.gradle:

dependencies {

compile 'mobi.inthepocket.android:ibeaconscanner:2.0.0'

}

Setup

If you want to scan for beacons in an activity or service, first initialize the library in your application class:

You need to set a target service to receive beacon notifications. This API has changed since the introduction of Android 8, we can only start JobIntentServices in the background. All beacon intents will be handled in this JobIntentService.

public class MyApplication extends Application

{

public void onCreate()

{

super.onCreate();

// initialize

IBeaconScanner.initialize(IBeaconScanner.newInitializer(this)

.setTargetService(BeaconActivityService.class)

.build());

}

}

Get notified of iBeacon enters and exits

You need the JobIntentService (described above) to receive beacon enters and exits.

public class BeaconActivityService extends JobIntentService

{

protected void onHandleWork(@NonNull final Intent intent)

{

// This is the beacon object containing UUID, major and minor info

final Beacon beacon = intent.getParcelableExtra(BluetoothScanBroadcastReceiver.IBEACON_SCAN_BEACON_DETECTION);

// This flag will be true if it is an enter event that triggered this service

final boolean enteredBeacon = intent.getBooleanExtra(BluetoothScanBroadcastReceiver.IBEACON_SCAN_BEACON_ENTERED, false);

// This flag will be true if it is an exit event that triggered this service

final boolean exitedBeacon = intent.getBooleanExtra(BluetoothScanBroadcastReceiver.IBEACON_SCAN_BEACON_EXITED, false);

// Here you can do something with the beacon trigger

}

}

Create a Beacon object

final Beacon beacon = Beacon.newBuilder()

.setUUID("84be19d4-797d-11e5-8bcf-feff819cdc9f")

.setMajor(1)

.setMinor(2)

.build();

Pass beacons you want to monitor

Pass one or more beacons to the library to start getting enter or exit notifies:

IBeaconScanner.getInstance().startMonitoring(beacon);

License

IBEACON-SCANNER-ANDROID is freely distributable under the terms of the MIT license.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值