vidyo.io Android SDK:视频来电通知机制及定向呼叫方法咨询
Hey there! Let me walk you through how to call specific user groups and handle incoming call notifications with the Vidyo.io Android SDK—based on my hands-on experience with the tool.
Vidyo.io’s core model revolves around rooms for multi-party calls, so targeting a specific user group typically ties into creating and managing dedicated rooms for those groups. Here’s how to approach it:
Key Workflow Steps
- Maintain User Group Data: First, you’ll need your own backend system to track which users belong to which groups (Vidyo SDK doesn’t handle user grouping natively). Store each user’s Vidyo ID (or the auth token they use to join rooms) alongside their group membership.
- Create a Group-Specific Room: When initiating a call for a group, have your backend create a dedicated room via the Vidyo.io API. You can set room permissions (like "invite-only") to ensure only your target group can join.
- Notify Group Members: Send the room ID, call context, and auth tokens (if needed) to all users in the group—usually via your push notification service (more on that later).
- Join the Room: On the Android side, use the
VidyoConnectorto connect users to the group room.
Quick Code Snippet for Joining a Group Room
// Initialize the VidyoConnector (do this once, e.g., in your CallActivity) VidyoConnector vidyoConnector = new VidyoConnector( this, binding.videoView, // Your VideoView for rendering the call VidyoConnector.ConnectorViewStyle.VIDYO_CONNECTORVIEWSTYLE_Default, "YOUR_DEVELOPER_KEY", // Replace with your Vidyo dev key new VidyoConnector.IConnect() { @Override public void onSuccess() { // Handle successful connection (e.g., update UI) } @Override public void onError(VidyoConnector.VidyoError error) { // Show error message to user } } ); // Connect to the group room when the user accepts the call vidyoConnector.connectToRoom( "GROUP_ROOM_ID", // From your backend "USER_DISPLAY_NAME", // User's name in the call "USER_AUTH_TOKEN", // Auth token for room access "" // Optional metadata );
Vidyo.io doesn’t include built-in push notifications, so you’ll need to pair it with a third-party service like Firebase Cloud Messaging (FCM) to alert users of incoming calls—whether the app is in the foreground or background.
Foreground App Handling
When the app is open, you can use Vidyo’s callback listeners to detect when someone joins the room (if the user is already connected) or listen for incoming invite signals from your backend:
- Use
VidyoConnector.IRegisterParticipantEventListenerto track participant joins:vidyoConnector.registerParticipantEventListener(new VidyoConnector.IParticipantEventListener() { @Override public void onParticipantJoined(VidyoParticipant participant) { // Show an in-app alert for incoming participant Toast.makeText(CallActivity.this, participant.getDisplayName() + " joined the call", Toast.LENGTH_SHORT).show(); } });
Background App Handling
For when the app is closed or in the background, FCM is your go-to:
- Integrate FCM: Set up FCM in your Android project, get the device token for each user, and store it in your backend alongside their user/group data.
- Trigger Push from Backend: When a group call is initiated, your backend sends an FCM message to all users in the target group. Include critical data like room ID, caller name, and call context in the message payload.
- Handle FCM Message: Create a
FirebaseMessagingServiceto receive the push and show a high-priority notification that launches your call activity when tapped.
Example FCM Notification Handler
public class CallNotificationService extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { // Extract call data from the FCM payload String roomId = remoteMessage.getData().get("roomId"); String callerName = remoteMessage.getData().get("callerName"); // Build the incoming call notification Intent callIntent = new Intent(this, CallActivity.class); callIntent.putExtra("ROOM_ID", roomId); callIntent.putExtra("CALLER_NAME", callerName); callIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity( this, 0, callIntent, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE ); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "CALL_CHANNEL") .setSmallIcon(R.drawable.ic_incoming_call) .setContentTitle("Incoming Group Call") .setContentText(callerName + " is calling your group") .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_CALL) .setContentIntent(pendingIntent) .setAutoCancel(true); // Create notification channel for Android O+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( "CALL_CHANNEL", "Incoming Calls", NotificationManager.IMPORTANCE_HIGH ); NotificationManager notificationManager = getSystemService(NotificationManager.class); notificationManager.createNotificationChannel(channel); } // Show the notification NotificationManagerCompat.from(this).notify(1, notificationBuilder.build()); } }
Important Notes
- Permissions: For Android 13+, request the
POST_NOTIFICATIONSpermission to show notifications. - Room Security: Always use auth tokens for room access to prevent unauthorized users from joining group calls.
- Background Execution: Ensure your app has the necessary background permissions to receive FCM messages reliably.
内容的提问来源于stack exchange,提问作者Udit Kapahi

