Manage profiles using SDK
A configuration Profile includes the scanner configuration and Workflow Rules. Profiles are identified using a unique profile name (ID).
Profile commands, like all commands that trigger an action on a scanner, are queued in Insight Mobile by default.
By providing a boolean valued extra com.proglove.api.extra.REPLACE_QUEUE
or a special flag in PgCommandParams
, this behavior can be changed to replace the queue with the new command.
To learn more, see Command queueing in Insight Mobile.
Change an active profile
To change the active configuration profile using SDK, call changeConfigProfile()
on your PgManager
reference with the following parameters:
PgCommand
object holding thePgConfigProfile
and optionalPgCommandParams
. The containingPgConfigProfile
must have a set profile name (profileId
).The object implementing
IPgConfigProfileCallback
. After the profile is successfully set (or in case of any errors), theIPgConfigProfileCallback
is called with the relevant information.
You can also broadcast an Intent with the following data:
Action:
com.proglove.api.CHANGE_CONFIG_PROFILE
Extra: String in
com.proglove.api.extra.CONFIG_PROFILE_ID
Activation is successful if the profile with the specified ID exists in the configuration file.
val profileName: String = "myProfileToSet" pgManager.changeConfigProfile( PgCommand(PgConfigProfile(profileName)), object : IPgConfigProfileCallback { override fun onConfigProfileChanged(profile: PgConfigProfile) { runOnUiThread { Toast.makeText( applicationContext, "${profile.profileId} set successfully", Toast.LENGTH_LONG ).show() } } override fun onError(error: PgError) { runOnUiThread { Toast.makeText( applicationContext, "Failed to set $profileName - $error", Toast.LENGTH_LONG ).show() } } } )
val profileName: String = "myProfileToSet" val intent = Intent() intent.setAction("com.proglove.api.CHANGE_CONFIG_PROFILE") intent.putExtra("com.proglove.api.extra.CONFIG_PROFILE_ID", profileName) sendBroadcast(intent)
Note
Explicit activation is only successful if the profile with the specified ID exists in the configuration file. Trying to replace an active profile with a non-existing profile ID using the SDK, returns an error. When changing it via Intent, there is no possibility to return an error.
Profiles can only be changed when Insight Mobile is running.
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), theIPgGetConfigProfilesCallback
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
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() } } } )
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)