License
Activate a NexPDF license key in an Android app, check which modules it unlocks, and handle license errors.
Call NexPdfLicense.initialize once per process, before other NexPDF calls, typically in
Application.onCreate(). It accepts the license XML file's text or the bare NEX2. key. See
Licensing for how keys are issued and bound.
Activate
val rc = NexPdfLicense.initialize(this)The key is read from, in order:
- the manifest meta-data
com.nexdevit.nexpdf.license_key; assets/nexpdf_license.xml.
<application android:name=".App">
<meta-data android:name="com.nexdevit.nexpdf.license_key" android:value="NEX2.…" />
</application>If neither is present, initialize returns -8.
The key is activated for the platform android and the app's package name (applicationId), read
from the Context, so a key issued for com.acme.app does nothing in another app.
It returns NexPdfLicense.LICENSED (2) for a commercial key and NexPdfLicense.TRIAL (1) for a
trial key.
Check the status
val status = JSONObject(NexPdfLicense.status())
Log.i("NexPDF", "${status.optString("state")} ${status.optString("tier")} ${status.optInt("days_left")}")status() returns the license JSON: state (unlicensed, trial, licensed), licensee, id,
tier, modules, expires_at, days_left and watermark. To check one module, look for it in
modules.
Handle errors
A rejected key returns a negative code, and NexPdfJni.lastError() gives the reason:
when (val rc = NexPdfLicense.initialize(this)) {
NexPdfLicense.LICENSED, NexPdfLicense.TRIAL -> Unit
-4 -> Log.e("NexPDF", "license expired: renew it in the dashboard")
-6, -7 -> Log.e("NexPDF", "license is for another platform or app id: ${NexPdfJni.lastError()}")
-8 -> Log.w("NexPDF", "no license configured")
else -> Log.e("NexPDF", "license rejected ($rc): ${NexPdfJni.lastError()}")
}| Code | Meaning |
|---|---|
| -1 | Malformed key |
| -2 | Bad signature |
| -3 | Unsupported key version |
| -4 | Expired |
| -5 | Not yet valid (check the clock) |
| -6 | Wrong platform |
| -7 | Wrong application id |
| -8 | No key in the manifest or the assets (initialize(context) only) |
A call that needs a module your key does not include fails, and lastError() says why:
if (!NexPdfJni.encryptAes256(doc.handle(), "user", "owner")) {
Log.e("NexPDF", NexPdfJni.lastError()) // the active license does not include the 'security' module
}Without a license, or after a rejected key, the SDK stays in viewer mode: it opens, renders, extracts text and searches, and rendered pages carry the "NexPDF • Unlicensed" watermark.