Skip to content

shokai/iBeacon-AndroidScala

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

iBeacon for Android Scala

Dependencies

Install Dependencies

% brew update
% brew install scala sbt

Usage

copy IBeacon.scala into your app.

AndroidManifest.xml

add user-permission

<manifest>
  <application> ~~ your app ~~ </application>
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
  <uses-feature android:name="android.hardware.bluetooth_le" android:required="true" />
</manifest>

Capture Beacons

import org.shokai.ibeacon.{IBeacon, Beacon};
class MainActivity extends Activity{

  lazy val iBeacon:IBeacon = new IBeacon(this)

  override def onCreate(savedInstanceState:Bundle){

    // capture all beacon packet
    iBeacon.onBeacon((beacon:Beacon) => {
      Log.v("iBeacon", s"UUID=${beacon.uuid} Major=${beacon.major} Minor=${beacon.minor} RSSI=${beacon.rssi}")
    })


    // when beacon appear
    iBeacon.onDiscover((beacon:Beacon) => {
      Log.v("iBeacon", s"discover ${beacon}")
    })

    // specify UUID, Major, Minor (hex-code)
    iBeacon.onDiscover("805D6740-F575-492A-8668-45E553EB9DF2", null, null, (beacon:Beacon) => {
      Log.v("iBeacon", s"discover UUID=${beacon.uuid} Major=${beacon.major}")
    })

  }

}

Detect Region

// Region by RSSI
iBeacon.onRegion("805D6740-F575-492A-8668-45E553EB9DF2", "0001", "0001", Range(-70,-50), (beacon:Beacon) => {
  Log.v("iBeacon", s"region(-70~-50) UUID=${beacon.uuid} RSSI=${beacon.rssi}")
})

iBeacon.onFar("805D6740-F575-492A-8668-45E553EB9DF2", "0001", "0001", (beacon:Beacon) => {
  Log.v("iBeacon", s"far: ${beacon.uuid}")
})

iBeacon.onNear("805D6740-F575-492A-8668-45E553EB9DF2", "0001", "0001", (beacon:Beacon) => {
  Log.v("iBeacon", s"near: ${beacon.uuid}")
})

iBeacon.onImmediate("805D6740-F575-492A-8668-45E553EB9DF2", "0001", "0001", (beacon:Beacon) => {
  Log.v("iBeacon", s"immediate: ${beacon.uuid}")
})

Remove Listener

val eid = iBeacon.onBeacon((beacon:Beacon) => {
  Log.v("iBeacon", s"UUID=${beacon.uuid}")
})

iBeacon.removeListener(eid)

SampleApps

sample app

service app

% cd SampleApps/iBeaconReader

or

% cd SampleApps/iBeaconService

Build

% android update project --path `pwd`
% sbt
> android:package-debug

Install

% adb devices
% adb install -r iBeaconReader-debug.apk

Develop

% sbt "~ android:run"

About

iBeacon Receiver for Android Scala

Resources

License

Stars

Watchers

Forks

Packages

No packages published