Age Categories API
Federal and/or state laws require app distribution stores to provide a method for third-party developers to verify users' ages.
Usage Terms
You may only use this API to:
- comply with legal requirements
- age-gate your app's content or functionalities
You may not transfer the age information off-device or share it with others unless doing so is necessary for the above purposes.
API
Include the following code in your application:
val ageVerificationAAH = AgeVerificationAAH(context)
val ageCategory = ageVerificationAAH.getAgeCategory()
if (ageCategory == AgeVerificationAAH.AGE_18_PLUS){
// TODO: do something here
} else {
// TODO: do something here
}
Android Manifest
<uses-permission android:name="com.lf.hub.ACCESS_AGE_CATEGORY" />
<queries>
<package android:name="com.lf.hub" />
</queries>
AgeVerificationAAH.kt
import android.content.Context
import androidx.core.net.toUri
class AgeVerificationAAH(private val context: Context) {
companion object {
const val AGE_UNKNOWN: Byte = 0
const val AGE_UNDER_18: Byte = 10
const val AGE_18_PLUS: Byte = 20
}
private val providerUri = "content://com.lf.hub.age".toUri()
fun getAgeCategory(): Byte? {
return try {
val bundle = context.contentResolver.call(
providerUri,
"getAgeCategory",
null,
null
)
if (bundle?.containsKey("ageCategory") == true) {
bundle.getByte("ageCategory")
} else {
null
}
} catch (_: Exception) {
null
}
}
}