ProGlove Documentation

Read profiles

Prerequisite: Insight Mobile (Android) version 1.7.0, and SDK version 1.4.0 or higher.

To get all available configuration profiles, call getConfigProfiles() on your PgManager reference with the following parameters:

  • The object implementing IPgGetConfigProfilesCallback. After reading the profiles (or in case of any errors), the IPgGetConfigProfilesCallback is called with the relevant information.

You can also broadcast an Intent with the following data:

  • Action: com.proglove.api.GET_CONFIG_PROFILES

  • No extras

Example 20. SDK
pgManager.getConfigProfiles(
    object : IPgGetConfigProfilesCallback {
        override fun onConfigProfilesReceived(profiles: Array<PgConfigProfile>) {
            val activeProfileId = profiles.firstOrNull { profile ->
                profile.isActive
            }?.profileId

            runOnUiThread {
                Toast.makeText(
                    applicationContext,
                    "Received ${profiles.size} config profiles with \"$activeProfileId\" as the active one",
                    Toast.LENGTH_LONG
                ).show()
            }
        }

        override fun onError(error: PgError) {
            runOnUiThread {
                Toast.makeText(
                    applicationContext,
                    "Failed to get profiles - $error",
                    Toast.LENGTH_LONG
                ).show()
            }
        }
    }
)


Example 21. Intent
val intent = Intent()
intent.setAction("com.proglove.api.GET_CONFIG_PROFILES")
sendBroadcast(intent)

// This will trigger the `com.proglove.api.CONFIG_PROFILES` broadcast from the Insight Mobile app.
// The broadcasted Intent contains the list of all configuration profiles and the active profile.  
// To receive the broadcasted intent:

// 1 Implement a broadcast receiver (in this case the class is called `MessageHandler`):

class MessageHandler : BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent?) {
        if (intent != null && intent.action == "com.proglove.api.CONFIG_PROFILES") {
            val configProfilesIds : Array<String> = intent.getStringArrayExtra(ApiConstants.EXTRA_CONFIG_PROFILE_ID) ?: emptyArray()
            val activeProfileId = intent.getStringExtra(ApiConstants.EXTRA_CONFIG_PROFILE_ACTIVE_ID) ?: ""

            runOnUiThread {
                Toast.makeText(
                    applicationContext,
                    "Received ${configProfilesIds.size} config profiles with \"$activeProfileId\" as the active one",
                    Toast.LENGTH_LONG
                ).show()
            }
        }
    }
}

// 2 define an IntentFilter filtering for the specified actions:

val messageHandler: MessageHandler = MessageHandler()
val filter = IntentFilter()
filter.addAction("com.proglove.api.CONFIG_PROFILES")
filter.addCategory(Intent.CATEGORY_DEFAULT)

// 3 Somewhere where a context is available (usually an Activity's or Service's onCreate):

context.registerReceiver(messageHandler, filter)

// Do not forget to unregister the receiver again, for example in onDestroy:

context.unregisterReceiver(messageHandler)