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

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

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

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

**Gradle:**

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

استبدل `<latest-version>` بالإصدار الحالي من [Maven Central](https://mvnrepository.com/artifact/com.pushwoosh/pushwoosh-calls).

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

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

```java
import com.pushwoosh.calls.PushwooshCallSettings;

PushwooshCallSettings.requestCallPermissions();
```

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

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

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

#### مثال Java

```java
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

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

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

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

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

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

```kotlin
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")
```

## روابط ذات صلة

- [نظرة عامة على Pushwoosh Android SDK](/ar/developer/pushwoosh-sdk/android-sdk/)
- [مصدر مكون Pushwoosh Call الإضافي](https://github.com/Pushwoosh/pushwoosh-android-sdk)
- [TelecomManager (وثائق Android)](https://developer.android.com/reference/android/telecom/TelecomManager)