# Token

Artifact: [androidx.browser:browser](https://developer.android.com/jetpack/androidx/releases/browser) [View Source](https://cs.android.com/search?q=file:androidx/browser/trusted/Token.java+class:androidx.browser.trusted.Token) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

*** ** * ** ***

<br />

```
class Token
```

<br />

*** ** * ** ***

Stores a package's identity, a combination of its package name and signing certificate. It is designed to be persistable as a `byte[]`, so you can do this:

```kotlin
Token token = Token.create(packageName, packageManager);
byte[] serialized = token.serialize();
// Persist serialized.

// Some time later...
Token verified = Token.deserialize(serialized);
verified.matches(packageName, packageManager);
```

## Summary

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token?` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#create(java.lang.String,android.content.pm.PackageManager)(packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, packageManager: https://developer.android.com/reference/android/content/pm/PackageManager.html)` Creates a `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token` for the given package, taking into account the package name and its signing signature. |
| `java-static https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#deserialize(byte[])(serialized: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>)` Reconstructs a `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token` from the output of its `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#serialize()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#matches(java.lang.String,android.content.pm.PackageManager)(packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, packageManager: https://developer.android.com/reference/android/content/pm/PackageManager.html)` Whether the given package matches the package that was used to create the original Token. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>` | `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#serialize()()` Serializes the `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token` to a form that can later be restored by the `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#deserialize(byte[])` method. |

## Public functions

### create

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
java-static fun create(packageName: String, packageManager: PackageManager): Token?
```

Creates a `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token` for the given package, taking into account the package name and its signing signature.

| Parameters |
|---|---|
| `packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The name of the package. |
| `packageManager: https://developer.android.com/reference/android/content/pm/PackageManager.html` | A `https://developer.android.com/reference/android/content/pm/PackageManager.html` to determine the signing information. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token?` | A `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token`. `null` if the provided package cannot be found (the app is not installed). |

### deserialize

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
java-static fun deserialize(serialized: ByteArray<Byte>): Token
```

Reconstructs a `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token` from the output of its `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#serialize()`.

| Parameters |
|---|---|
| `serialized: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>` | The result of a `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#serialize()` call. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token` | The deserialized Token. |

### matches

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
fun matches(packageName: String, packageManager: PackageManager): Boolean
```

Whether the given package matches the package that was used to create the original Token.

| Parameters |
|---|---|
| `packageName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | The name of the package. |
| `packageManager: https://developer.android.com/reference/android/content/pm/PackageManager.html` | A `https://developer.android.com/reference/android/content/pm/PackageManager.html` to get information about the package. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether the given package currently is the same as the one used to create the Token. |

### serialize

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/browser#1.2.0)

```
fun serialize(): Array<Byte>
```

Serializes the `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token` to a form that can later be restored by the `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token#deserialize(byte[])` method.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>` | A serialization of the `https://developer.android.com/reference/kotlin/androidx/browser/trusted/Token`. |