Sinch API 失败

问题描述

我正在尝试使用 Sinch SDK 创建一个基于 VoIP 的应用程序,但我不断收到错误消息。我遵循了演示应用程序,但我收到了那个错误。任何人都可以帮忙

6/28 21:18:35: Launching 'app' on Physical Device.
App restart successful without requiring a re-install.
$ adb shell am start -n "com.example.nhare/com.example.nhare.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 32112 on device 'samsung-sm_j610f-23ae061b'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
W/Componentdiscovery: Class com.google.firebase.dynamicloading.DynamicLoadingRegistrar is not an found.
I/FirebaseApp: Device unlocked: initializing all Firebase APIs for app [DEFAULT]
D/FirebaseAuth: Notifying id token listeners about user ( yNLPb9S17NXpfRSTMfNocK3pFU63 ).
I/FirebaseInitProvider: FirebaseApp initialization successful
I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to fallback implementation
D/PhoneWindow: forceLight changed to true [] from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4238 com.android.internal.policy.DecorView.updateColorViews:1510 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3216 android.view.Window.setFlags:1148 com.android.internal.policy.PhoneWindow.generateLayout:2444 
I/MultiWindowDecorSupport: updateCaptionType >> DecorView@ee252cc[],isFloating: false,isApplication: true,hasWindowDecorCaption: false,hasWindowControllerCallback: true
D/MultiWindowDecorSupport: setCaptionType = 0,DecorView = DecorView@ee252cc[]
W/m.example.nhar: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist,reflection,allowed)
W/m.example.nhar: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist,allowed)
D/ViewRootImpl@dd42505[MainActivity]: setView = com.android.internal.policy.DecorView@ee252cc TM=true MM=false
D/NetworkSecurityConfig: No Network Security Config specified,using platform default
D/ViewRootImpl@dd42505[MainActivity]: Relayout returned: old=(0,720,1480) new=(0,1480) req=(720,1480)0 dur=17 res=0x7 s={true 2342543360} ch=true
D/Openglrenderer: createReliableSurface : 0x968f0a40,0x8ba06000
I/AdrenoGLES: QUALCOMM build                   : d39f783,I79de86aa2c
    Build Date                       : 06/04/20
    OpenGL ES Shader Compiler Version: EV031.27.05.03
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.8.6.R1.10.00.00.578.029
    Remote Branch                    : NONE
    Reconstruct Branch               : nothing
    Build Config                     : S L 8.0.12 AArch32
I/AdrenoGLES: PFP: 0x003ff016,ME: 0x003ff041
W/Gralloc3: mapper 3.x is not supported
D/ViewRootImpl@dd42505[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager: prepareNavigationBarInfo() DecorView@ee252cc[MainActivity]
D/InputMethodManager: getNavigationBarColor() -855310
D/EmergencyMode: [EmergencyManager] android createPackageContext successful: com.example.nhare
D/InputMethodManager: prepareNavigationBarInfo() DecorView@ee252cc[MainActivity]
    getNavigationBarColor() -855310
V/InputMethodManager: Starting input: tba=com.example.nhare ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true,NavVisible : true,NavTrans : false
D/InputMethodManager: startInputInner - Id : 0
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
D/ViewRootImpl@dd42505[MainActivity]: MSG_RESIZED: frame=(0,1480) ci=(0,42,84) vi=(0,84) or=1
D/InputMethodManager: prepareNavigationBarInfo() DecorView@ee252cc[MainActivity]
    getNavigationBarColor() -855310
V/InputMethodManager: Starting input: tba=com.example.nhare ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true,NavTrans : false
D/InputMethodManager: startInputInner - Id : 0
W/ClassMapper: No setter/field for Contact found on class com.example.nhare.Contacts
I/chatty: uid=10317(com.example.nhare) identical 1 line
W/ClassMapper: No setter/field for Contact found on class com.example.nhare.Contacts
D/ViewRootImpl@849c0db[Toast]: setView = android.widget.LinearLayout@48c0778 TM=true MM=false
V/Toast: Text: Pnli in android.widget.Toast$TN@8b5ee51
D/ViewRootImpl@849c0db[Toast]: Relayout returned: old=(0,1396) new=(282,1207,438,1284) req=(156,77)0 dur=21 res=0x7 s={true 2342492160} ch=true
D/Openglrenderer: createReliableSurface : 0x8b91d400,0x8b9f9800
D/ViewRootImpl@849c0db[Toast]: MSG_RESIZED: frame=(282,1284) ci=(0,0) vi=(0,156,77) or=1
D/ViewRootImpl@849c0db[Toast]: dispatchDetachedFromWindow
D/InputTransport: Input channel destroyed: 'f168fa7',fd=85
D/ViewRootImpl@dd42505[MainActivity]: ViewPostIme pointer 0
D/ViewRootImpl@dd42505[MainActivity]: ViewPostIme pointer 1
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@f9a1e8d
D/PhoneWindow: forceLight changed to true [] from com.android.internal.policy.PhoneWindow.updateForceLightNavigationBar:4238 com.android.internal.policy.DecorView.updateColorViews:1510 com.android.internal.policy.PhoneWindow.dispatchWindowAttributesChanged:3216 android.view.Window.setFlags:1148 com.android.internal.policy.PhoneWindow.generateLayout:2444 
I/MultiWindowDecorSupport: updateCaptionType >> DecorView@da2d966[],DecorView = DecorView@da2d966[]
D/ReLinkerLibraryLoader: Beginning load of sinch-android-rtc...
D/ReLinkerLibraryLoader: sinch-android-rtc (3.17.6) was loaded normally!
I/SinchClient: RebRTC revision:616f2e312
E/m.example.nhar: No package ID ff found for ID 0xffffffff.
E/m.example.nhar: No package ID ff found for ID 0xffffffff.
I/Org.webrtc.Logging: EglBase14Impl: SDK version: 29. isEGL14Supported: true
I/Org.webrtc.Logging: EglBase14Impl: Using OpenGL ES version 2
I/Org.webrtc.Logging: Eglrenderer: Initializing Eglrenderer
W/m.example.nhar: Accessing hidden method Ljava/lang/invoke/LambdaMetafactory;->Metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; (blacklist,linking,denied)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.nhare,PID: 32112
    java.lang.NoSuchMethodError: No static method Metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite; in class Ljava/lang/invoke/LambdaMetafactory; or its super classes (declaration of 'java.lang.invoke.LambdaMetafactory' appears in /apex/com.android.runtime/javalib/core-oj.jar)
        at org.webrtc.Eglrenderer.init(UnkNown Source:61)
        at org.webrtc.Eglrenderer.init(UnkNown Source:1)
        at org.webrtc.SurfaceEglrenderer.init(UnkNown Source:18)
        at org.webrtc.SurfaceVieWrenderer.init(UnkNown Source:12)
        at org.webrtc.SurfaceVieWrenderer.init(UnkNown Source:7)
        at com.sinch.android.rtc.internal.client.video.DefaultVideoController.<init>(UnkNown Source:57)
        at com.sinch.android.rtc.internal.client.DefaultSinchClient.<init>(UnkNown Source:314)
        at com.sinch.android.rtc.internal.client.InternalSinchClientFactory.createSinchClient(UnkNown Source:60)
        at com.sinch.android.rtc.DefaultSinchClientBuilder.build(UnkNown Source:38)
        at com.example.nhare.ChatsActivity.onCreate(ChatsActivity.java:111)
        at android.app.Activity.performCreate(Activity.java:7955)
        at android.app.Activity.performCreate(Activity.java:7944)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:3531)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3703)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2216)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7948)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

任何可以提供帮助的人请帮忙,下面是我的活动代码

    package com.example.nhare;


import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;



import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.linearlayoutmanager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.sinch.android.rtc.PushPair;
import com.sinch.android.rtc.Sinch;
import com.sinch.android.rtc.SinchClient;
import com.sinch.android.rtc.SinchClientListener;
import com.sinch.android.rtc.calling.Call;
import com.sinch.android.rtc.calling.CallClientListener;
import com.sinch.android.rtc.calling.CallListener;
import com.sinch.android.rtc.internal.natives.jni.CallClient;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChatsActivity extends AppCompatActivity
{

    private String messageReceiverID,messageReceiverName,messageReceiverImage,messageSenderID;

    private TextView userLastSeen,userName;
    private ImageView userImage,ChatsBack,ChatsCallButton;


    private FirebaseAuth mAuth;
    private DatabaseReference RootRef;

    private ImageButton ChatsSendMessageButton;
    private ImageButton ChatsSendAudioButton;
    private EditText ChatsuserMessageInput;
    private Toolbar ChatToolBar;
    private ImageButton SendMessageButton,AttachFile,Emojibutton;

    private final List<Messages> messagesList = new ArrayList<>();
    private linearlayoutmanager linearlayoutmanager;
    private MessageAdapter messageAdapter;
    private RecyclerView userMessagesList;

    private SinchClient sinchClient;
     Call call;

    private String currentChatName,saveCurrentTime,saveCurrentDate;


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

         mAuth = FirebaseAuth.getInstance();
         messageSenderID = mAuth.getCurrentUser().getUid();
         RootRef = FirebaseDatabase.getInstance().getReference();

          messageReceiverID = getIntent().getExtras().get("visit_user_id").toString();
          messageReceiverName = getIntent().getExtras().get("visit_user_name").toString();
          messageReceiverImage = getIntent().getExtras().get("visit_image").toString();

        Initializefields();

        userName.setText(messageReceiverName);

        //Setting up the Sinch API for calls
        sinchClient = Sinch.getSinchClientBuilder()
                .context(this)
                .userId(messageReceiverID)
              .applicationKey("fc7fcfab-c116-4bac-a346-c23f14342577")
              .applicationSecret("OuOgjnyZfUe+2TGSCobfog==")
              .environmentHost("clientapi.sinch.com")
              .build();

        //Set up Sinch to start listening for incoming calls
        sinchClient.setSupportCalling(true);
        sinchClient.startListeningOnActiveConnection();

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

        sinchClient.start();

        ChatsSendMessageButton.setonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view)
            {
                SendMessage();
            }
        });


        displayLastSeen();

        ChatsCallButton.setonClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view)
            {
              // make a call!
              if(call == null)
              {
                  call = sinchClient.getCallClient().callUser(messageReceiverID);
                  call.addCallListener(new SinchCallListener());

                  openCallerDialog(call);
              }

          }
        });

        ChatsBack.setonClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                Intent ChatBackButton = new Intent(ChatsActivity.this,MainActivity.class);
                startActivity(ChatBackButton);
            }
        });


        ChatsuserMessageInput.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s,int start,int count,int after)
            {

            }

            @Override
            public void onTextChanged(CharSequence charSequence,int before,int count)
            {
                String message=charSequence.toString();

                ExchangeSendAudioWithASendMessage(message);
            }

            @Override
            public void afterTextChanged(Editable s)
            {

            }
        });

    }

    private void openCallerDialog(final Call call)
    {
            AlertDialog alertDialogCall = new AlertDialog.Builder(ChatsActivity.this).create();
            alertDialogCall.setTitle("ALERT");
            alertDialogCall.setMessage("CALLING");
            alertDialogCall.setButton(AlertDialog.BUTTON_NEUTRAL,"Hang Up",new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog,int which)
                {
                    dialog.dismiss();
                    call.hangup();
                }
            });
    }

    private void ExchangeSendAudioWithASendMessage(String message)
    {
        if (message.isEmpty())
        {
            ChatsSendAudioButton.setVisibility(View.VISIBLE);
        }
        else
        {
            ChatsSendAudioButton.setVisibility(View.INVISIBLE);

            ChatsSendMessageButton.setVisibility(View.VISIBLE);
        }

    }


    private void Initializefields()
    {
            ChatToolBar = (Toolbar) findViewById(R.id.chat_toolbar);
            setSupportActionBar(ChatToolBar);

            ActionBar actionBar = getSupportActionBar();
            actionBar.setdisplayHomeAsUpEnabled(false);
            actionBar.setdisplayShowCustomEnabled(true);
            actionBar.setdisplayShowTitleEnabled(false);

            LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View actionBarView = layoutInflater.inflate(R.layout.custom_chat_bar,null);
            actionBar.setCustomView(actionBarView);

            ChatsSendMessageButton = (ImageButton) findViewById(R.id.chats_send_message_button);
            ChatsSendAudioButton = (ImageButton) findViewById(R.id.chats_send_audio_button);
            AttachFile = (ImageButton) findViewById(R.id.attach_button);
            Emojibutton = (ImageButton) findViewById(R.id.emoji_button);
            ChatsBack = (ImageView) findViewById(R.id.chats_back);
            ChatsuserMessageInput = (EditText) findViewById(R.id.chats_input_group_message);


            userName = (TextView) findViewById(R.id.custom_profile_name);
            userLastSeen = (TextView) findViewById(R.id.custom_user_last_seen);

            ChatsCallButton = (ImageView) findViewById(R.id.chats_menu_call);

            messageAdapter = new MessageAdapter(messagesList);
            userMessagesList = (RecyclerView) findViewById(R.id.chats_private_messages_list_of_users);
            linearlayoutmanager = new linearlayoutmanager(this);
            userMessagesList.setLayoutManager(linearlayoutmanager);
            userMessagesList.setAdapter(messageAdapter);

            Calendar calendar = Calendar.getInstance();

            SimpleDateFormat currentDate = new SimpleDateFormat("MMM dd,yyyy");
            saveCurrentDate = currentDate.format(calendar.getTime());

            SimpleDateFormat currentTime = new SimpleDateFormat("hh:mm a");
            saveCurrentTime = currentTime.format(calendar.getTime());

    }


    private void displayLastSeen()
    {
        RootRef.child("Users").child(messageReceiverID)
                .addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot)
                    {
                        if (dataSnapshot.child("userState").hasChild("state"))
                        {
                            String state = dataSnapshot.child("userState").child("state").getValue().toString();
                            String date = dataSnapshot.child("userState").child("date").getValue().toString();
                            String time = dataSnapshot.child("userState").child("time").getValue().toString();

                            if (state.equals("online"))
                            {
                                userLastSeen.setText("online");
                            }
                            else if (state.equals("offline"))
                            {
                                userLastSeen.setText("Last Seen: " + date + " " + time);
                            }
                        }
                        else
                        {
                            userLastSeen.setText("offline");
                        }
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });
    }


    @Override
    protected void onStart()
    {
        super.onStart();

        RootRef.child("Messages").child(messageSenderID).child(messageReceiverID)
                .addChildEventListener(new ChildEventListener() {
                    @Override
                    public void onChildAdded(DataSnapshot dataSnapshot,String s)
                    {
                        Messages messages = dataSnapshot.getValue(Messages.class);

                        messagesList.add(messages);

                        messageAdapter.notifyDataSetChanged();

                        userMessagesList.smoothScrollToPosition(userMessagesList.getAdapter().getItemCount());
                    }

                    @Override
                    public void onChildChanged(DataSnapshot dataSnapshot,String s) {

                    }

                    @Override
                    public void onChildRemoved(DataSnapshot dataSnapshot) {

                    }

                    @Override
                    public void onChildMoved(DataSnapshot dataSnapshot,String s) {

                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }
                });
    }



    private void SendMessage()
    {
        String messageText = ChatsuserMessageInput.getText().toString();

        if (TextUtils.isEmpty(messageText))
        {
            Toast.makeText(this,"first write your message...",Toast.LENGTH_SHORT).show();
        }
        else
        {
            String messageSenderRef = "Messages/" + messageSenderID + "/" + messageReceiverID;
            String messageReceiverRef = "Messages/" + messageReceiverID + "/" + messageSenderID;

            DatabaseReference userMessageKeyRef = RootRef.child("Messages")
                    .child(messageSenderID).child(messageReceiverID).push();

            String messagePushID = userMessageKeyRef.getKey();

            Map messageTextBody = new HashMap();
            messageTextBody.put("message",messageText);
            messageTextBody.put("type","text");
            messageTextBody.put("from",messageSenderID);
            messageTextBody.put("to",messageReceiverID);
            messageTextBody.put("messageID",messagePushID);
            messageTextBody.put("time",saveCurrentTime);
            messageTextBody.put("date",saveCurrentDate);

            Map messageBodyDetails = new HashMap();
            messageBodyDetails.put(messageSenderRef + "/" + messagePushID,messageTextBody);
            messageBodyDetails.put( messageReceiverRef + "/" + messagePushID,messageTextBody);

            RootRef.updateChildren(messageBodyDetails).addOnCompleteListener(new OnCompleteListener() {
                @Override
                public void onComplete(@NonNull Task task)
                {
                    if (task.isSuccessful())
                    {
                        Toast.makeText(ChatsActivity.this,"Message Sent Successfully...",Toast.LENGTH_SHORT).show();
                    }
                    else
                    {
                        Toast.makeText(ChatsActivity.this,"Error",Toast.LENGTH_SHORT).show();
                    }
                    ChatsuserMessageInput.setText("");
                }
            });
        }
    }

    private class SinchCallListener implements CallListener
    {

        @Override
        public void onCallProgressing(Call call)
        {
            //call is ringing
            Toast.makeText(getApplicationContext(),"Ringing . . .",Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCallEstablished(Call call)
        {
            //incoming call was picked up
            Toast.makeText(getApplicationContext(),"Call Picked",Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCallEnded(Call endedCall)
        {
            //call ended by either party
            Toast.makeText(getApplicationContext(),"Call Ended",Toast.LENGTH_LONG).show();
            call = null;
            endedCall.hangup();
        }

        @Override
        public void onShouldSendPushNotification(Call call,List<PushPair> list)
        {
            //don't worry about this right Now
        }
    }

    private class SinchCallClientListener implements CallClientListener
    {

        @Override
        public void onIncomingCall(com.sinch.android.rtc.calling.CallClient callClient,final Call call)
        {
            //Create the dialog for the incoming call here
            //Temporary UI
            AlertDialog alertDialog = new AlertDialog.Builder(ChatsActivity.this).create();
            //AlertDialog.setTitle("INCOMING CALL");
            alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL,"Reject",int which)
                {
                    dialog.dismiss();
                    call.hangup();

                }
            });

            alertDialog.setButton(AlertDialog.BUTTON_POSITIVE,"Pick",int which)
                {
                    dialog.dismiss();
                    call.answer();
                    call.addCallListener(new SinchCallListener());
                    Toast.makeText(getApplicationContext(),"Call Started",Toast.LENGTH_LONG).show();
                }
            });

            alertDialog.show();

        }
    }



}

我的目标是进行基于 VoIP 的呼叫,我也尝试过 Liblinphone 和 restcomm,但找不到 Sinch 提供的有意义的可跟踪演示,也欢迎任何替代方案

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)