انتقل إلى المحتوى

مكالمات VoIP على Android

يدعم Pushwoosh إشعارات المكالمات على غرار VoIP لنظام Android باستخدام الوحدة pushwoosh-calls. يتيح ذلك واجهة مستخدم المكالمات الأصلية وإدارة دورة الحياة باستخدام Android’s telecom stack.

1. أضف الوحدة pushwoosh-calls

Anchor link to

تأكد من تضمين تبعية pushwoosh-calls في مشروعك.

Gradle:

dependencies {
implementation 'com.pushwoosh:pushwoosh-calls:<latest-version>'
}

استبدل <latest-version> بالإصدار الحالي من Maven Central.

2. اطلب أذونات المكالمات

Anchor link to

اطلب الأذونات المطلوبة في وقت التشغيل باستخدام الدالة المساعدة:

import com.pushwoosh.calls.PushwooshCallSettings;
PushwooshCallSettings.requestCallPermissions();

يتعامل هذا مع طلب الأذونات مثل READ_PHONE_NUMBERS، وهو ضروري للتعامل السليم مع المكالمات.

3. نفّذ CallEventListener وسجّلها في Manifest

Anchor link to

للتعامل مع المكالمات الواردة والأحداث، نفّذ واجهة CallEventListener في تطبيقك.

مثال Java

Anchor link to
public class DemoCallEventListener implements CallEventListener {
@Override
public void onAnswer(@NonNull PushwooshVoIPMessage voIPMessage, int videoState) {
// implement this method to navigate to your in-call UI
Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
@Override
public void onReject(@NonNull PushwooshVoIPMessage voIPMessage) {
// override this method to handle dismissed calls
}
@Override
public void onDisconnect(@NonNull PushwooshVoIPMessage voIPMessage) {
// override this method to handle disconnected calls
}
@Override
public void onCreateIncomingConnection(@Nullable Bundle payload) {
// this is the earliest point when call notification payload is accessible in your app,
// use it to prepare your app UI for user interactions with call notifications
}
@Override
public void onCallAdded(@NonNull PushwooshVoIPMessage voIPMessage) {
// extension method of InCallService, provides customization options for paired Wearable devices
}
@Override
public void onCallRemoved(@NonNull PushwooshVoIPMessage voIPMessage) {
// extension method of InCallService, provides customization options for paired Wearable devices
}
}

AndroidManifest.xml

Anchor link to

صرح عن فئة المستمع الخاصة بك باستخدام وسم <meta-data>:

<meta-data
android:name="com.pushwoosh.CALL_EVENT_LISTENER"
android:value="com.pushwoosh.demoapp.DemoCallEventListener" />

4. تكوين إعدادات المكالمات (اختياري)

Anchor link to

استخدم PushwooshCallSettings لضبط سلوك المكالمات والأصوات وإعدادات العرض بدقة.

مثال على الاستخدام

Anchor link to
import com.pushwoosh.calls.PushwooshCallSettings
PushwooshCallSettings.setPhoneAccount("com.pushwoosh.voip")
PushwooshCallSettings.setPhoneAccountHandle("PushwooshCallHandle")
PushwooshCallSettings.setIncomingCallChannelName("Incoming Calls")
PushwooshCallSettings.setOngoingCallChannelName("Ongoing Calls")
PushwooshCallSettings.setCallSound("custom_ringtone.mp3")

روابط ذات صلة

Anchor link to