See Action section for more details on Intent broadcast extras and statuses.
- Register receiver (e.g. in
AndroidManifest.xml
):
<!-- ... -->
<receiver android:name="com.mycompany.myapp.MyInstallationBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.digitalturbine.ignite.service.action.STATUS_CHANGED" />
</intent-filter>
</receiver>
<!-- ... -->
- Pass receiver name during the
install
:
// Initialization
// Install application via uri string and listen to updates using broadcast receiver action
val file = File("${context.filesDir}", "fortnite.apk")
val uriString = file.toUri().toString()
IgniteServiceSdk.instance().install(uriString, action = buildInstallAction())
// ...
private fun buildInstallAction() = Bundle().apply {
putString("receiver", MyInstallationBroadcastReceiver::class.java.canonicalName)
}
// ...
// Below is the example of MyInstallationBroadcastReceiver class implementation to receive updates about installation
class MyInstallationBroadcastReceiver: BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
Log.i(TAG, "Install application intent=$intent")
var progress = ""
val percentage = intent?.getDoubleExtra(STATUS_PROGRESS, -1.0)
if ((percentage ?: 0.0) > -1.0) {
progress = "${percentage?.roundToInt()}%"
}
Log.i(TAG, "BroadcastReceiver: ${intent?.getStringExtra(STATUS_MESSAGE)} $progress")
// Do other work related to the status
}
private companion object {
const val STATUS_MESSAGE = "com.dt.ignite.service.extras.STATUS_MESSAGE"
const val STATUS_PROGRESS: String = "com.dt.ignite.service.extras.STATUS_PROGRESS"
}
}