Initialize SDK and get device details
To initialise the SDK add the below line of code with the public key you retrieved from Sense client panel. If you don't have a public key create new one and call that below function.
How to Install
toast-icon
Requirements
  1. Use Android 5.1 (API level 21) and above.
  2. Use Kotlin version 1.6.10 and above.
  3. Add READ_PHONE_STATE Permission in Android Manifest for device information (Optional).
Note:If the application does not have the listed permissions, the values collected using those permissions will be ignored. To provide a valid device details, we recommend employing as much permission as possible based on your use-case.
  1. Add Dependency build.gradle file
    copy-icon
    dependencies {
        implementation 'ai.gosense:devicesecurity:1.0.4'
    }
    Sync Gradle to synchronize all the dependencies in your Android project.
  2. Import SDK
    copy-icon
    import ai.gosense.devicesecurity.Sense
    import ai.gosense.devicesecurity.SenseConfig
  3. Initialize SDK
    Add the following line of code to initialize it with the api key you obtained from the Sense Client panel. If you don't have a api key create new one.
    Sense.prewarm() is internal now. initSDK() calls it automatically.
    copy-icon
    val config = SenseConfig(
        apiKey = "Your API Key",
        senseInfo = true, // true or false
        allowGeoLocation = true, // true or false
        tag = ""// Whatever you need, just mention the string here like home, contact, etc.
    )
    Sense.initSDK(activity, config)
    Sense Config Information
    • Sense Config InformationIf you pass senseInfo as true in above config means, it will return addtional Information like Request ID, First seen, Last seen, IP Address with SenseID. Otherwise it will return only SenseID and Request.
    • If you pass allowGeoLocation as true in above config means, it will return Device Location Information in Sense Details via our Server API.
  4. Get Device Details
    Use the below code to get the Device Details.
    copy-icon
    Sense.getSenseDetails(this)
  5. Implement Listener
    Set and Implement our listener to receive the Callback details.
    copy-icon
    Sense.getSenseDetails(object : Sense.SenseListener {
        override fun onSuccess(data: String) {
            // success callback 
        }
        override fun onFailure(message: String) {
            // failure callback
        }
    })
    If you want runtime security alerts, implement SenseRaspListener on your Activity or Fragment host.
  6. Location Permission (optional)
    Request only the permissions required by the features you enable. READ_PHONE_STATE is optional and is used only for call/SIM-related signals. Do not request READ_PRIVILEGED_PHONE_STATE: it is reserved for privileged system apps and is never granted to ordinary Play-distributed apps.
    copy-icon
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
  7. Proguard Rules (Optional)
    If you encounter any problem in your integration related to Proguard, you can use add the below lines Proguard Rules.
    copy-icon
    -keep,allowobfuscation,allowshrinking interface retrofit2.Call
    -keep,allowobfuscation,allowshrinking class retrofit2.Response
    -keep,allowobfuscation,allowshrinking class kotlin.coroutines.** { *; }
    -dontwarn ai.gosense.**
    -keep class ai.gosense.** {*;}
  8. Sample Program
    Here you can find the demonstration to do the integration.
    copy-icon
    import ai.gosense.devicesecurity.Sense
    import ai.gosense.devicesecurity.SenseConfig
    import ai.gosense.devicesecurity.SenseRaspListener
    
    class MainActivity : AppCompatActivity(), SenseRaspListener {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContentView(R.layout.activity_main)
    
            val config = SenseConfig(
                apiKey = "Your API Key", //Replace with your Client Public API Key
                 senseInfo = true, // true or false
                 allowGeoLocation = true, // true or false
                 tag = ""// Whatever you need, just mention the string here like home, contact, etc.
            )
    
            // Initialize SDK. prewarm() is handled internally.
            Sense.initSDK(this, config)
    
            // Fetch device details
            getSenseDetails()
        }
    
        private fun getSenseDetails() {
            Sense.getSenseDetails(object : Sense.SenseListener {
                override fun onSuccess(data: String) {
                    // Handle success callback
                }
                override fun onFailure(message: String) {
                    // Handle failure callback
                }
            })
        }
    
        override fun onAppIntegrityThreatDetected(isOn: Boolean) {
            // Handle clone / tamper alert
        }
    }