0

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");
        }
    }

}
help-info.de
  • 6,695
  • 16
  • 39
  • 41
Sam
  • 241
  • 3
  • 7
  • what you tried so far? Which document you followed for this example can you share it please? – Nadeem Taj Aug 29 '21 at 06:17
  • I followed the sich documentation, but I think the issue with their own API or might be not working in worldwide. – Sam Aug 29 '21 at 18:27
  • and name of that API is? – Nadeem Taj Aug 29 '21 at 18:50
  • Could you share more error details, please? – HoRn Aug 30 '21 at 06:28
  • If you are facing a crash when building with Android Studio, do you have the output from Logcat? The version of the API would be good to know. There are also Sample Apps for Android that can be used to verify the API functionality packaged with the SDK download: https://developers.sinch.com/docs/voice-video-client/sdk-downloads/ – Roland Sep 16 '21 at 05:45

0 Answers0