GShockAPI

@RequiresApi(value = 26)
class GShockAPI(context: Context)

This class contains all the API functions. This should the the main interface to the library.

Here is how to use it:

private val api = GShockAPI(this)

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
GlobalScope.launch {
api.waitForConnection(this)
api.getPressedButton()
api.getWatchName()
api.getBatteryLevel()
api.getTimer()
api.getAppInfo()
api.getHomeTime()
api.setTime()
...
}
}
}

Constructors

Link copied to clipboard
constructor(context: Context)

Functions

Link copied to clipboard

Clears all events (reminders) from the watch. Up to 5 events are supported.

Link copied to clipboard
fun disconnect(context: Context)

Disconnect from the watch

Link copied to clipboard
suspend fun getAlarms(): ArrayList<Alarm>

Gets the current alarms from the watch. Up to 5 alarms are supported on the watch.

Link copied to clipboard
suspend fun getAppInfo(): String

Gets and internally sets app info to the watch. This is needed to re-enable lower-right button after the watch has been reset or BLE has been cleared. Call this function after each time the connection has been established.

Link copied to clipboard
suspend fun getBatteryLevel(): Int

Get Battery level.

Link copied to clipboard
suspend fun getDSTForWorldCities(cityNumber: Int): String

Get the Daylight Saving Time for a particular World City set on the watch. There are 6 world cities that can be stored.

Link copied to clipboard

Get the DST state of the watch.

Link copied to clipboard
suspend fun getError(): String
Link copied to clipboard

Gets the current events (reminders) from the watch. Up to 5 events are supported.

Link copied to clipboard
suspend fun getHomeTime(): String

Get Home Time, (Home City).

Link copied to clipboard

This function tells us which button was pressed on the watch to initiate the connection. Remember, the connection between the phone and the watch can only be initiated from the watch.

Link copied to clipboard
suspend fun getSettings(): Settings

Get settings from the watch. Example:

Link copied to clipboard
suspend fun getTimer(): Int

Get Timer value in seconds.

Link copied to clipboard
suspend fun getWatchName(): String

Get the name of the watch.

Link copied to clipboard
suspend fun getWatchTemperature(): Int

Get Watch Temperature.

Link copied to clipboard
suspend fun getWorldCities(cityNumber: Int): String

Get the name for a particular World City set on the watch. There are 6 world cities that can be stored.

Link copied to clipboard

This function tells us if the connection was initiated by short-pressing the lower-right button on the watch, also known as ACTION BUTTON

Link copied to clipboard

This function tells us if the connection was initiated automatically by the watch, without the user pressing any button. This happens if Auto-Time is set in the setting. In this case, the watch will periodically connect at around 00:30, 06:30, 12:30 and 18:30

Link copied to clipboard

Tells us if Bluetooth is currently enabled on the phone. If not, the app can take action to enable it.

Link copied to clipboard

Returns a Boolean value indicating if the watch is currently commenced to the phone

Link copied to clipboard

This function tells us if the connection was initiated by ling-pressing the lower-right button on the watch, used to activate FIND PHONE action

Link copied to clipboard

This function tells us if the connection was initiated by long-pressing the lower-left button on the watch

Link copied to clipboard
Link copied to clipboard
fun resetHand()
Link copied to clipboard
@RequiresApi(value = 26)
fun sendMessage(message: String)
Link copied to clipboard
fun setAlarms(alarms: ArrayList<Alarm>)

Sets alarms to the watch. Up to 5 alarms are supported on the watch.

Link copied to clipboard
fun setEvents(events: ArrayList<Event>)

Sets events (reminders) to the watch. Up to 5 events are supported.

Link copied to clipboard
fun setSettings(settings: Settings)

Set settings to the watch. Populate a Settings and call this function. Example:

Link copied to clipboard
suspend fun setTime(timeZone: String = TimeZone.getDefault().id)

Sets the current time on the watch from the time on the phone. In addition, it can optionally set the Home Time to the current time zone. If timezone changes during travel, the watch will automatically be set to the correct time and timezone after running this function.

Link copied to clipboard
fun setTimer(timerValue: Int)

Set Timer value in seconds.

Link copied to clipboard
fun stopScan()
Link copied to clipboard

Close the connection and free all associated resources.

Link copied to clipboard
Link copied to clipboard
suspend fun waitForConnection(deviceId: String? = "", deviceName: String? = "")

This function waits for the watch to connect to the phone. When connected, it returns and emmits a ConnectionSetupComplete event, which can inform other parts of the app that the connection has taken place.