# Google.Play.Instant.CookieApi

Provides methods that an instant app can use to store a persistent cookie or that an installed app can use to retrieve the cookie that it persisted as an instant app.

## Summary

This is a C# implementation of some of the Java methods available in [Google Play Services' PackageManagerCompat class](https://developers.google.com/android/reference/com/google/android/gms/instantapps/PackageManagerCompat).

| ### Public static functions ||
|---|---|
| `https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a2902cf2c402d5df647dcab52a0c40a4f()` | `string` Gets the instant app cookie for this app as a string. |
| `https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1af0f6a8f11830e8022d3a84ad8edeff03()` | `byte[]` Gets the instant app cookie for this app as bytes. |
| `https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a05b37df64201df4a4db968a4403f2261()` | `int` Gets the maximum size in bytes of the cookie data an instant app can store on the device. |
| `https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a72b0c8c0c931ac0e427f237b2bad4874(string cookie)` | `bool` Sets the instant app cookie as a string for the calling app. |
| `https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a4454e780eb003833a079c38465a39640(byte[] cookie)` | `bool` Sets the instant app cookie as bytes for the calling app. |

| ### Classes ||
|---|---|
| [Google.Play.Instant.CookieApi.CookieApiException](https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi/CookieApiException) | An exception thrown by the methods of [CookieApi](https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi) if there is a failure while making a call to [Google](https://developer.android.com/reference/unity/namespace/Google#namespaceGoogle)[Play](https://developer.android.com/reference/unity/namespace/Google/Play#namespaceGoogle_1_1Play) Services. |

## Public static functions

### GetInstantAppCookie

```c#
string GetInstantAppCookie()
```
Gets the instant app cookie for this app as a string.

Assumes that the cookie was encoded with UTF-8, for example by [SetInstantAppCookie](https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a72b0c8c0c931ac0e427f237b2bad4874). See [GetInstantAppCookieBytes](https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1af0f6a8f11830e8022d3a84ad8edeff03) for more details.

<br />

Details Exceptions `CookieApiException` Thrown if there is a failure to obtain the cookie.

### GetInstantAppCookieBytes

```c#
byte[] GetInstantAppCookieBytes()
```
Gets the instant app cookie for this app as bytes.

Non instant apps and apps that were instant but were upgraded to normal apps can still access this API. For instant apps this cookie is cached for some time after uninstall while for normal apps the cookie is deleted after the app is uninstalled. The cookie is always present while the app is installed.

<br />

Details Exceptions `CookieApiException` Thrown if there is a failure to obtain the cookie.

### GetInstantAppCookieMaxSizeBytes

```c#
int GetInstantAppCookieMaxSizeBytes()
```
Gets the maximum size in bytes of the cookie data an instant app can store on the device.

<br />

Details Exceptions `CookieApiException` Thrown if there is a failure to obtain the size.

### SetInstantAppCookie

```c#
bool SetInstantAppCookie(
  string cookie
)
```
Sets the instant app cookie as a string for the calling app.

The cookie string will be encoded with UTF-8 and can be recalled using [GetInstantAppCookie](https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a2902cf2c402d5df647dcab52a0c40a4f). See [SetInstantAppCookieBytes](https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a4454e780eb003833a079c38465a39640) for more details. Note: the length of the cookie string may not be directly comparable to the size limit indicated by [GetInstantAppCookieMaxSizeBytes](https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a05b37df64201df4a4db968a4403f2261).

<br />

Details Parameters `cookie` The cookie string. Exceptions `CookieApiException` Thrown if there is a failure to set the cookie. **Returns** True if the cookie was set. False if cookie is too large or I/O fails.

### SetInstantAppCookieBytes

```c#
bool SetInstantAppCookieBytes(
  byte[] cookie
)
```
Sets the instant app cookie as bytes for the calling app.

Non instant apps and apps that were instant but were upgraded to normal apps can still access this API. For instant apps this cookie is cached for some time after uninstall while for normal apps the cookie is deleted after the app is uninstalled. The cookie is always present while the app is installed. The cookie size is limited by [GetInstantAppCookieMaxSizeBytes](https://developer.android.com/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a05b37df64201df4a4db968a4403f2261). If the provided cookie size is over the limit, this method returns false. Passing null or an empty array clears the cookie.

<br />

Details Parameters `cookie` The cookie bytes. Exceptions `CookieApiException` Thrown if there is a failure to set the cookie. **Returns** True if the cookie was set. False if cookie is too large or I/O fails.