Stay organized with collections
Save and categorize content based on your preferences.
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.
Public static functions
GetInstantAppCookie
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. See GetInstantAppCookieBytes for more details.
Details |
Exceptions |
CookieApiException
|
Thrown if there is a failure to obtain the cookie.
|
|
GetInstantAppCookieBytes
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.
Details |
Exceptions |
CookieApiException
|
Thrown if there is a failure to obtain the cookie.
|
|
GetInstantAppCookieMaxSizeBytes
int GetInstantAppCookieMaxSizeBytes()
Gets the maximum size in bytes of the cookie data an instant app can store on the device.
Details |
Exceptions |
CookieApiException
|
Thrown if there is a failure to obtain the size.
|
|
SetInstantAppCookie
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. See SetInstantAppCookieBytes for more details. Note: the length of the cookie string may not be directly comparable to the size limit indicated by GetInstantAppCookieMaxSizeBytes.
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
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. If the provided cookie size is over the limit, this method returns false. Passing null or an empty array clears the cookie.
Details |
Parameters |
|
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.
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2021-03-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2021-03-18 UTC."],[],[],null,["# Google.Play.Instant.CookieApi Class Reference\n\nGoogle.Play.Instant.CookieApi\n=============================\n\nProvides 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.\n\nSummary\n-------\n\nThis 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).\n\n| ### Public static functions ||\n|------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|\n| [GetInstantAppCookie](#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a2902cf2c402d5df647dcab52a0c40a4f)`()` | `string` Gets the instant app cookie for this app as a string. |\n| [GetInstantAppCookieBytes](#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1af0f6a8f11830e8022d3a84ad8edeff03)`()` | `byte[]` Gets the instant app cookie for this app as bytes. |\n| [GetInstantAppCookieMaxSizeBytes](#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. |\n| [SetInstantAppCookie](#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a72b0c8c0c931ac0e427f237b2bad4874)`(string cookie)` | `bool` Sets the instant app cookie as a string for the calling app. |\n| [SetInstantAppCookieBytes](#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a4454e780eb003833a079c38465a39640)`(byte[] cookie)` | `bool` Sets the instant app cookie as bytes for the calling app. |\n\n| ### Classes ||\n|-----------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Google.Play.Instant.CookieApi.CookieApiException](/reference/unity/class/Google/Play/Instant/CookieApi/CookieApiException) | An exception thrown by the methods of [CookieApi](/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](/reference/unity/namespace/Google#namespaceGoogle)[Play](/reference/unity/namespace/Google/Play#namespaceGoogle_1_1Play) Services. |\n\nPublic static functions\n-----------------------\n\n### GetInstantAppCookie\n\n```c#\nstring GetInstantAppCookie()\n``` \nGets the instant app cookie for this app as a string.\n\nAssumes that the cookie was encoded with UTF-8, for example by [SetInstantAppCookie](/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a72b0c8c0c931ac0e427f237b2bad4874). See [GetInstantAppCookieBytes](/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1af0f6a8f11830e8022d3a84ad8edeff03) for more details.\n\n\u003cbr /\u003e\n\n| Details ||\n|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Exceptions | |----------------------|----------------------------------------------------| | `CookieApiException` | Thrown if there is a failure to obtain the cookie. | |\n\n### GetInstantAppCookieBytes\n\n```c#\nbyte[] GetInstantAppCookieBytes()\n``` \nGets the instant app cookie for this app as bytes.\n\nNon 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.\n\n\u003cbr /\u003e\n\n| Details ||\n|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Exceptions | |----------------------|----------------------------------------------------| | `CookieApiException` | Thrown if there is a failure to obtain the cookie. | |\n\n### GetInstantAppCookieMaxSizeBytes\n\n```c#\nint GetInstantAppCookieMaxSizeBytes()\n``` \nGets the maximum size in bytes of the cookie data an instant app can store on the device.\n\n\u003cbr /\u003e\n\n| Details ||\n|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Exceptions | |----------------------|--------------------------------------------------| | `CookieApiException` | Thrown if there is a failure to obtain the size. | |\n\n### SetInstantAppCookie\n\n```c#\nbool SetInstantAppCookie(\n string cookie\n)\n``` \nSets the instant app cookie as a string for the calling app.\n\nThe cookie string will be encoded with UTF-8 and can be recalled using [GetInstantAppCookie](/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a2902cf2c402d5df647dcab52a0c40a4f). See [SetInstantAppCookieBytes](/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](/reference/unity/class/Google/Play/Instant/CookieApi#classGoogle_1_1Play_1_1Instant_1_1CookieApi_1a05b37df64201df4a4db968a4403f2261).\n\n\u003cbr /\u003e\n\n| Details ||\n|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Parameters | |----------|--------------------| | `cookie` | The cookie string. | |\n| Exceptions | |----------------------|-------------------------------------------------| | `CookieApiException` | Thrown if there is a failure to set the cookie. | |\n| **Returns** | True if the cookie was set. False if cookie is too large or I/O fails. |\n\n### SetInstantAppCookieBytes\n\n```c#\nbool SetInstantAppCookieBytes(\n byte[] cookie\n)\n``` \nSets the instant app cookie as bytes for the calling app.\n\nNon 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](/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.\n\n\u003cbr /\u003e\n\n| Details ||\n|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Parameters | |----------|-------------------| | `cookie` | The cookie bytes. | |\n| Exceptions | |----------------------|-------------------------------------------------| | `CookieApiException` | Thrown if there is a failure to set the cookie. | |\n| **Returns** | True if the cookie was set. False if cookie is too large or I/O fails. |"]]