Push Notifications
To receive push notifications, you'll need to:
- Configure your push notification provider in the Stream Dashboard.
- Add the client-side integration for the chosen provider in your app.
We support the following providers:
We ship an individual artifact for each provider to make client-side integration quick and simple. See their individual documentation pages linked above for setup details.
Customizing Push Notifications
If you want, you can also customize how push notifications work.
You can customize push notifications in the following ways:
- Adding an
intent-filter: Lets you choose activities that will be invoked when the Push Notification is handled by the SDK - Extending
CompatibilityStreamNotificationHandler: Lets you customize how specific notifications are shown, while reusing the default implementation for the rest.
Adding intent filters in your Android Manifest
You need to create the activities that will be called when the push notification is handled by the SDK and declare an intent-filter with the actions they support.
These are the actions that we provide:
io.getstream.video.android.action.INCOMING_CALL: Action used to process an incoming call. TheActivitythat handles this action should show options to accept/reject the call. You can use our RigningCallContent component to build your screen. This screen can be shown when the device is locked, by adding some arguments in the manifest.io.getstream.video.android.action.OUTGOING_CALL: Action used to process an outgoing call. TheActivitythat handles this action should show options to cancel the call. You can use our RigningCallContent component to build your screen.io.getstream.video.android.action.ACCEPT_CALL: Action used to accept an incoming call. TheActivitythat handles this action should accept the call and show the call screen. You can use our CallContent component to build your screen.io.getstream.video.android.action.ONGOING_CALL: Action used to get back to an already ongoing call. TheActivitythat handles this action should show the call screen. You can use our CallContent component to build your screen.io.getstream.video.android.action.LIVE_CALL: Action used to go into a live call. TheActivitythat handles this action should show the live call screen. You can use our LivestreamPlayer component to build your screen.
These actions need to be included in the AndroidManifest file:
<manifest>
<application>
<activity
android:name=".IncomingCallActivity"
android:exported="false"
android:showOnLockScreen="true"
android:showWhenLocked="true">
<intent-filter android:priority="1">
<action android:name="io.getstream.video.android.action.INCOMING_CALL" />
</intent-filter>
</activity>
<activity
android:name=".OutgoingCallActivity"
android:exported="false"
android:showOnLockScreen="true"
android:showWhenLocked="true">
<intent-filter android:priority="1">
<action android:name="io.getstream.video.android.action.OUTGOING_CALL" />
</intent-filter>
</activity>
<activity
android:name=".AcceptCallActivity"
android:exported="false">
<intent-filter android:priority="1">
<action android:name="io.getstream.video.android.action.ACCEPT_CALL" />
</intent-filter>
</activity>
<activity
android:name=".CallActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter android:priority="1">
<action android:name="io.getstream.video.android.action.ONGOING_CALL" />
</intent-filter>
</activity>
<activity
android:name=".LiveCallActivity"
android:exported="false">
<intent-filter android:priority="1">
<action android:name="io.getstream.video.android.action.LIVE_CALL" />
</intent-filter>
</activity>
</application>
</manifest>You can handle multiple intent-filter within a single Activity if you prefer.
Once you have declared your activities in the manifest, including the intent-filter for the actions defined previously, your activities will be started when a Push Notification arrives to the device. The Intent that your Activity will receive contains the StreamCallId for the call you need to handle. To obtain the StreamCallId we provide an extension function that you can use:
class IncomingCallActivity : AppCompatActivity {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val streamCallId = intent.streamCallId(NotificationHandler.INTENT_EXTRA_CALL_CID)
[...]
}
}Extending CompatibilityStreamNotificationHandler
The SDK lets you define the theming and behavior of the notification UI that users see after they receive a push notification.
The NotificationHandler interface has many methods, so instead of implementing it from scratch, extend CompatibilityStreamNotificationHandler, the SDK's default NotificationHandler, and override only the notifications you want to change:
import android.app.Application
import android.app.Notification
import io.getstream.video.android.core.notifications.handlers.CompatibilityStreamNotificationHandler
import io.getstream.video.android.model.StreamCallId
class MyNotificationHandler(application: Application) :
CompatibilityStreamNotificationHandler(application) {
// Called when a Ringing Call arrives (outgoing or incoming)
override fun onRingingCall(
callId: StreamCallId,
callDisplayName: String,
payload: Map<String, Any?>,
) {
// Show your own notification, or call super to keep the default one
}
// Called when a Live Call arrives
override fun onLiveCall(
callId: StreamCallId,
callDisplayName: String,
payload: Map<String, Any?>,
) {
// Show your own notification
}
// Called for other call notifications
override fun onNotification(
callId: StreamCallId,
callDisplayName: String,
payload: Map<String, Any?>,
) {
// Show your own notification
}
// Called to create the notification for the active call
override fun getOngoingCallNotification(
callId: StreamCallId,
callDisplayName: String?,
isOutgoingCall: Boolean,
remoteParticipantCount: Int,
payload: Map<String, Any?>,
): Notification? {
// Return your own notification, or call super to keep the default one
return super.getOngoingCallNotification(
callId,
callDisplayName,
isOutgoingCall,
remoteParticipantCount,
payload,
)
}
}Finally, pass your NotificationHandler implementation to the StreamVideoBuilder when initializing the Stream Android SDK:
import io.getstream.video.android.core.StreamVideoBuilder
import io.getstream.video.android.core.notifications.NotificationConfig
val notificationHandler = MyNotificationHandler(application)
val notificationConfig = NotificationConfig(
pushDeviceGenerators = listOf(
// PushDeviceGenerator
),
notificationHandler = notificationHandler
)
StreamVideoBuilder(
context = context,
user = user,
token = token,
apiKey = apiKey,
notificationConfig = notificationConfig,
).build()Handling Push Notification Permissions
Starting from Android API level 33 (Android 13+), all apps need to request runtime permissions to be able to show notifications to the user.
Runtime Permission Request
For Android 13+ (API level 33+), you need to request the POST_NOTIFICATIONS permission:
import android.Manifest
import android.os.Build
import androidx.activity.result.contract.ActivityResultContracts
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val permissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { granted ->
// Permission result handled
}
permissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS)
}Don't forget to add the permission to your AndroidManifest.xml:
<manifest>
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
</manifest>Configuring SDK Permission Behavior
When you integrate Stream Push Notification, our SDK will request permission to post notification whenever it is needed.
If you want to configure this behavior, you can configure it within the NotificationConfig class.
val notificationConfig = NotificationConfig(
pushDeviceGenerators = listOf(
// PushDeviceGenerator
),
notificationHandler = notificationHandler,
// This lambda will be called to check if permission needs to be requested by the SDK or not.
requestPermissionOnAppLaunch = { true }
)