Уведомление о входящем звонке

Разрабатываю приложение для Android(видео звонки с использованием Agora.io) и столкнулся с такой проблемой как вызов уведомлений. Мне нужно что бы при вызове абонента у принимающего создавалось уведомление о входящем звонке.

файл Manifest:

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />

    <application
        android:name=".Notification"
        android:allowBackup="true"
        android:icon="@mipmap/app_logo"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.VideoCalls">
        <activity
            android:name=".AgoraUI"
            android:exported="false" />
        <activity
            android:name=".SearchActivity"
            android:exported="false" />
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SecondActivity" />

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />
    </application>

Вот пример кода: public class Notification extends Application {

    public static final String CHANNEL_ID = "asd";

    @Override
    public void onCreate() {
        super.onCreate();
        createNotificationChannel();
    }

    private void createNotificationChannel() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            NotificationChannel notificationChannel = new NotificationChannel(
                    CHANNEL_ID,
                    "asd",
                    NotificationManager.IMPORTANCE_HIGH
            );

            NotificationManager manager = getSystemService(NotificationManager.class);
            manager.createNotificationChannel(notificationChannel);
        }
    }
}

SecondActivity:

public void makeNotification() {
        RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification);

        Notification customNotification = new NotificationCompat.Builder(this, CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_menu_camera)
                .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
                .setCustomContentView(notificationLayout)
                .addAction(R.id.accept_button, "accept", btnYes(SecondActivity))
                .build();

        notificationManagerCompat.notify(1, customNotification);
        
    }
public PendingIntent btnYes(View view) {
        if (rtmCallManager != null && globalRemoteInvitation != null) {
            rtmCallManager.acceptRemoteInvitation(globalRemoteInvitation, new ResultCallback<Void>() {
                @Override
                public void onSuccess(Void unused) {
                    callToUser(globalRemoteInvitation.getCallerId(), false);
                }

                @Override
                public void onFailure(ErrorInfo errorInfo) {
                }
            });

        }
        return null;
    }
 @Override
            public void onRemoteInvitationReceived(RemoteInvitation remoteInvitation) {
             globalRemoteInvitation = remoteInvitation;
                makeNotification();


            }

Соединение абонентов работает исправно, но проблема заключается в том, что уведомления приходят только тогда, когда у меня открыто SecondActivity, а так же не получается назначить действия на кнопку "accept" в уведомлении.

Пробовал кучу разных вариантов, но проблему так и не получилось решить.


Ответы (0 шт):