"SinchClient not started" The main problem in android studio

280 Views Asked by At

I am facing this problem for the last two weeks. Can you help me why this problem occurs?

Error occur at this line allClient.callPhoneNumber("+16315192247");

Please check it. Every time it crashes.

package com.eureka.voicecallinapk;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.sinch.android.rtc.PushPair;
import com.sinch.android.rtc.Sinch;
import com.sinch.android.rtc.SinchClient;
import com.sinch.android.rtc.SinchError;
import com.sinch.android.rtc.calling.Call;
import com.sinch.android.rtc.calling.CallClient;
import com.sinch.android.rtc.calling.CallClientListener;
import com.sinch.android.rtc.calling.CallListener;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    public static final String APP_KEY = "b7258284-f0dnd-4734-afec-210d387d****";
//i do it for security because i am posting here
    public static final String APP_SECRET = "k76tOLgz+kSdKL7ULYsH**==";
    public static final String ENVIRONMENT = "clientapi.sinch.com";


    public Call call;
    private TextView callState;
    public SinchClient sinchClient;
    private Button button;
    private String callerId;
    private String recipientId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent intent = getIntent();
        callerId = intent.getStringExtra("callerId");
        recipientId = intent.getStringExtra("recipientId");


        sinchClient = Sinch.getSinchClientBuilder()
                .context(MainActivity.this)
                .userId("172976")
                .applicationKey(APP_KEY)
                .applicationSecret(APP_SECRET)
                .environmentHost(ENVIRONMENT)
                .build();

        sinchClient.setSupportCalling(true);
        sinchClient.startListeningOnActiveConnection();


        sinchClient.start();

//        sinchClient.getCallClient().addCallClientListener(new SinchCallClientListener());

        button = findViewById(R.id.button);
        callState = findViewById(R.id.callState);

        button.setOnClickListener(view -> {


            if (call == null) {

                try {
                    boolean s=isStarted();
                    Log.d("checksinch", String.valueOf(s));
                CallClient callClient = sinchClient.getCallClient();
                callClient.callPhoneNumber("+16315192247"); // Error occur at this line "SinchClient not started"
                //callClient.callPhoneNumber("+16315192247");
//                    call = sinchClient.getCallClient().callPhoneNumber("+46000000000.");
//                    call.addCallListener(new SinchCallListener());
                button.setText("Hang Up");
                }catch (Exception e){
                    Log.d("checksinch", e.getMessage());
                }

            } else {
                call.hangup();
                button.setText("Call");

            }


        });

        }
    private boolean isStarted() {
        return (sinchClient != null && sinchClient.isStarted());
    }

    private class SinchCallListener implements CallListener {
        @Override
        public void onCallEnded(Call endedCall) {
            call = null;
            SinchError a = endedCall.getDetails().getError();
            button.setText("Call");
            callState.setText("");
            setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
        }

        @Override
        public void onCallEstablished(Call establishedCall) {
            callState.setText("connected");
            setVolumeControlStream(AudioManager.STREAM_VOICE_CALL);
        }

        @Override
        public void onCallProgressing(Call progressingCall) {
            callState.setText("ringing");
        }

        @Override
        public void onShouldSendPushNotification(Call call, List<PushPair> pushPairs) {
        }
    }

    private class SinchCallClientListener implements CallClientListener {
        @Override
        public void onIncomingCall(CallClient callClient, Call incomingCall) {
            call = incomingCall;
            Toast.makeText(MainActivity.this, "incoming call", Toast.LENGTH_SHORT).show();
            call.answer();
            call.addCallListener(new SinchCallListener());
            button.setText("Hang Up");
        }
    }

}
0

There are 0 best solutions below