# Snapping Games

The following section deals primarily with the code used in capture of live game information for SnapOdds Operator. If your use case requires game odds to be presented, the information captured by SnapOdds Operator is fed into SnapOdds Sports Media to correlate the game odds information, as described in [Snapping Games and Presenting Odds](/docs/mobile-sdk/android/snapodds-sport-media/snapping-games-and-presenting-odds.md)

## Implementation

1. Ensure the SDK is initialized according to instructions listed in the [**Android Initialization**](/docs/mobile-sdk/android/snapodds-operator/initialization.md) section.
2. Ensure your class conforms to `SnapFragmentResultListener` or `SnapActivityResultListener`
3. Instantiate `SnapFragment` or `SnapActivity` with your desired `SnapConfiguration` and your `SnapFragmentResultListener` or `SnapActivityResultListener`
4. Handle the result in your listener implementation.

{% hint style="info" %}
The sport event that is returned contains the SportRadar Match ID as the property **externalId**. Several other ID providers like Kambi, Donbest, and more are available on request.
{% endhint %}

## Live Game Capture Code Example

In order to snap a TV image and search for a sporting event, it is necessary to create and present an instance of `SnapFragment` via the `newInstance` class method. Snap settings can be customized by configuring the `SnapConfiguration` passed to the initializer. The `SnapFragmentResultListener` will receive a callback once a sporting event was successfully snapped.

The following code presents a `SnapFragment` with the default configuration.

```kotlin
SnapFragment.newInstance(SnapConfiguration(), this)
```

If you do not want or need to customize the snapping configuration, you can also omit the `configuration` parameter.

Once a sporting event is successfully 'snapped', the following method is called in `SnapFragmentResultListener`:

```swift
override fun snapFragmentDidSnapSportEvent(
        fragment: SnapFragment,
        sportEvent: SportEventSnapResultEntry
    ) {
    // This is the SportRadar Match ID by default. 
    // Other ID providers are available on request
    val externalProviderId = sportEvent.externalId
}
```

After a successfull snap (and call of the listener method) the `SnapFragment` automatically stops snapping. If you do not present any follow-up UI and you want to continue snapping, you can call `continueSnapping()` on the `SnapFragment`.&#x20;

If the sporting event is not successfully snapped, the values above are not returned, and an error message will appear in the viewfinder:\
\&#xNAN;*"Your snap returned no results. Make sure your TV is visible in the viewfinder"*

### Camera Permissions Required before Presenting Snap

Applications must request user permission for camera access, and camera access is required for the app to function. For this reason, your application should be set to ask permission from the user to access the camera, and to receive said permission, before presenting the Snap UI. The following code will set your application to request and receive permission prior to opening Snap UI:

```kotlin
val isGranted = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED
if (isGranted) {
    startActivity(Intent(context, MySnapActivity::class.java))
} else {
    requestPermissions(arrayOf(Manifest.permission.CAMERA), PERMISSION_REQUEST_CAMERA)
}
```

## Alternative Example using SnapActivity

In addition to using the `SnapFragment` directly, you can also use the `SnapActivity` provided by the SDK. In that case, use the class method on `SnapActivity` to retrieve an intent and pass a `SnapActivityResultListener`. The `SnapActivityResultListener` will receive a callback once a sporting event was successfully snapped.

The following code presents a SnapActivity with the default configuration.

```
val intent = SnapActivity.intentForSportsOperator(this, SnapConfiguration(), this)
startActivity(intent)
```

If you do not want or need to customize the snapping configuration, you can also omit the `configuration` parameter.

Once a sporting event is successfully snapped, the following method is called in SnapActivityResultsListener:

```
override fun snapActivityDidSnapSportEvent(
    activity: SnapActivity,
    fragment: SnapFragment,
    sportEvent: SportEventSnapResultEntry) {
    
}
```

After a successfull snap (and call of the listener method) the `SnapFragment` (used for UI presentation in the `SnapActivity`) automatically stops snapping. If you do not present any follow-up UI and you want to continue snapping, you can call `continueSnapping()` on the `SnapFragment`.&#x20;

If you want to dismiss the activity and continue your own UI, you need to call `activity.finish()` on the `SnapActivity`.

## Recommendations

### Present Snap as a separate Activity

It is recommended that you present the SnapFragment as a separate Activity.

### Limit to portrait

Currently the Snap UI is only optimized for portrait orientation. It is recommended to present and limit the Activity containing a SnapFragment be limited to portrait orientation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.snapodds.com/docs/mobile-sdk/android/snapodds-operator/snapping-games.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
