@@ -5,7 +5,6 @@ import android.os.Bundle
55import android.util.Log
66import android.util.TypedValue
77import android.view.View
8- import android.widget.LinearLayout
98import android.widget.TextView
109import androidx.appcompat.app.AppCompatActivity
1110import androidx.lifecycle.lifecycleScope
@@ -23,7 +22,6 @@ import kotlin.reflect.full.memberProperties
2322 * Main activity demonstrating the MaxMind Device Tracker usage.
2423 */
2524class MainActivity : AppCompatActivity () {
26-
2725 private lateinit var binding: ActivityMainBinding
2826 private var logText = StringBuilder ()
2927 private val json = Json { prettyPrint = true }
@@ -60,6 +58,7 @@ class MainActivity : AppCompatActivity() {
6058 binding.btnSend.isEnabled = false
6159 }
6260
61+ @Suppress(" TooGenericExceptionCaught" )
6362 private fun initializeSdk () {
6463 try {
6564 if (DeviceTracker .isInitialized()) {
@@ -70,9 +69,11 @@ class MainActivity : AppCompatActivity() {
7069
7170 // Create SDK configuration
7271 // Note: Replace with your actual MaxMind account ID
73- val config = SdkConfig .Builder (123456 ) // Demo account ID - replace with real one
74- .enableLogging(true )
75- .build()
72+ val config =
73+ SdkConfig
74+ .Builder (123456 ) // Demo account ID - replace with real one
75+ .enableLogging(true )
76+ .build()
7677
7778 // Initialize SDK
7879 DeviceTracker .initialize(this , config)
@@ -89,6 +90,7 @@ class MainActivity : AppCompatActivity() {
8990 }
9091 }
9192
93+ @Suppress(" TooGenericExceptionCaught" , " NestedBlockDepth" )
9294 private fun collectDeviceData () {
9395 try {
9496 val sdk = DeviceTracker .getInstance()
@@ -100,19 +102,27 @@ class MainActivity : AppCompatActivity() {
100102 appendLog(" Brand: ${deviceData.build.brand} " )
101103 appendLog(" OS Version: ${deviceData.build.osVersion} " )
102104 appendLog(" SDK Version: ${deviceData.build.sdkVersion} " )
103- appendLog(" Screen: ${deviceData.display.widthPixels} x${deviceData.display.heightPixels} (${deviceData.display.densityDpi} dpi)" )
105+ val display = deviceData.display
106+ appendLog(" Screen: ${display.widthPixels} x${display.heightPixels} (${display.densityDpi} dpi)" )
104107 appendLog(" Timestamp: ${deviceData.deviceTime} " )
105108 appendLog(" " )
109+ appendLog(" 🔑 IDs:" )
110+ appendLog(" Stored ID: ${deviceData.storedID.id ? : " (none)" } " )
111+ appendLog(" MediaDRM ID: ${deviceData.deviceIDs.mediaDrmID ? : " (none)" } " )
112+ appendLog(" Android ID: ${deviceData.deviceIDs.androidID ? : " (none)" } " )
113+ appendLog(" " )
106114
107115 // Dynamically add collapsible sections for each property
108116 deviceData::class .memberProperties.forEach { prop ->
109117 val value = prop.getter.call(deviceData)
110118 if (value != null ) {
111- val content = try {
112- json.encodeToString(serializer(prop.returnType), value)
113- } catch (e: Exception ) {
114- value.toString()
115- }
119+ @Suppress(" SwallowedException" )
120+ val content =
121+ try {
122+ json.encodeToString(serializer(prop.returnType), value)
123+ } catch (e: Exception ) {
124+ value.toString()
125+ }
116126 addCollapsibleSection(prop.name, content)
117127 }
118128 }
@@ -131,24 +141,29 @@ class MainActivity : AppCompatActivity() {
131141 }
132142 }
133143
134- private fun addCollapsibleSection (title : String , content : String ) {
135- val header = TextView (this ).apply {
136- text = " ▶ $title "
137- setTypeface(typeface, Typeface .BOLD )
138- setTextSize(TypedValue .COMPLEX_UNIT_SP , 14f )
139- setPadding(0 , dpToPx(12 ), 0 , dpToPx(4 ))
140- setTextColor(getColor(R .color.section_header))
141- }
144+ private fun addCollapsibleSection (
145+ title : String ,
146+ content : String ,
147+ ) {
148+ val header =
149+ TextView (this ).apply {
150+ text = " ▶ $title "
151+ setTypeface(typeface, Typeface .BOLD )
152+ setTextSize(TypedValue .COMPLEX_UNIT_SP , 14f )
153+ setPadding(0 , dpToPx(12 ), 0 , dpToPx(4 ))
154+ setTextColor(getColor(R .color.section_header))
155+ }
142156
143- val contentView = TextView (this ).apply {
144- text = content
145- setTextSize(TypedValue .COMPLEX_UNIT_SP , 12f )
146- typeface = Typeface .MONOSPACE
147- setPadding(dpToPx(16 ), dpToPx(4 ), 0 , dpToPx(12 ))
148- setTextColor(getColor(R .color.section_content))
149- setBackgroundColor(getColor(R .color.surface))
150- visibility = View .GONE
151- }
157+ val contentView =
158+ TextView (this ).apply {
159+ text = content
160+ setTextSize(TypedValue .COMPLEX_UNIT_SP , 12f )
161+ typeface = Typeface .MONOSPACE
162+ setPadding(dpToPx(16 ), dpToPx(4 ), 0 , dpToPx(12 ))
163+ setTextColor(getColor(R .color.section_content))
164+ setBackgroundColor(getColor(R .color.surface))
165+ visibility = View .GONE
166+ }
152167
153168 header.setOnClickListener {
154169 if (contentView.visibility == View .GONE ) {
@@ -165,12 +180,14 @@ class MainActivity : AppCompatActivity() {
165180 }
166181
167182 private fun dpToPx (dp : Int ): Int =
168- TypedValue .applyDimension(
169- TypedValue .COMPLEX_UNIT_DIP ,
170- dp.toFloat(),
171- resources.displayMetrics
172- ).toInt()
173-
183+ TypedValue
184+ .applyDimension(
185+ TypedValue .COMPLEX_UNIT_DIP ,
186+ dp.toFloat(),
187+ resources.displayMetrics,
188+ ).toInt()
189+
190+ @Suppress(" TooGenericExceptionCaught" )
174191 private fun sendDeviceData () {
175192 try {
176193 val sdk = DeviceTracker .getInstance()
@@ -188,7 +205,7 @@ class MainActivity : AppCompatActivity() {
188205 appendLog(" ✗ $errorMsg " )
189206 Log .e(TAG , errorMsg, error)
190207 showMessage(errorMsg)
191- }
208+ },
192209 )
193210 }
194211 } catch (e: Exception ) {
0 commit comments