Sinch conference call error

匿名 (未验证) 提交于 2019-12-03 00:44:02

问题:

I'm trying to start a conference call from my android app but it doesn't work, what I tried is:

Intent intent1 = new Intent(CreateGroupCallActivity.this,SinchClientService.class);             intent1.setAction(SinchClientService.ACTION_GROUP_CALL);             String id = String.valueOf(uid) + "-" + call_id.getText().toString();             intent1.putExtra(SinchClientService.INTENT_EXTRA_ID,id);             startService(intent1); 

and in my SinchClientService:

if(intent.getAction().equals(ACTION_GROUP_CALL))             {                 String id = intent.getStringExtra(INTENT_EXTRA_ID);                 if(id != null)                     groupCall(id);             }  public void groupCall(String id) {         if (mCallClient != null) {             Call call = mCallClient.callConference(id);             CurrentCall.currentCall = call;              Log.d("call", "entered");              Intent intent = new Intent(this, GroupCallService.class);             startService(intent);         }     } 

and here is my GroupCallService

public class GroupCallServiceInterface extends Binder {         public String getCallState() {             return mCall.getState().toString();         }          public String getCallerId() {             return mCall.getRemoteUserId();         }          public String getCallerName() {             if(mFriendName == null)                 return "The call creator isn't a friend with you";              return mFriendName;         }          public void endCall() {             GroupCallService.this.endCall();         }          public void answerCall() {             GroupCallService.this.answer();         }          public void declineCall() {             GroupCallService.this.decline();         }     }      @Override     public void onCreate() {         super.onCreate();          //connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);          timeZone = TimeZone.getDefault();          if(CurrentCall.currentCall == null)             stopSelf();          mCall = CurrentCall.currentCall;         mCall.addCallListener(this);          mAudioPlayer = new AudioPlayer(this);          mFriendName = ChatDatabaseHandler.getInstance(this).getFriendName(mCall.getRemoteUserId());          /*location = intent.getStringExtra("location");         longitude = intent.getStringExtra("longitde");         latitude = intent.getStringExtra("latitude");*/          mExecutorService = Executors.newSingleThreadExecutor();          mExecutorService.submit(new Runnable() {              @Override             public void run() {                 showNotification();             }         });          if(mCall.getDirection() == CallDirection.INCOMING)         {             mAudioPlayer.playRingtone();              Intent intent = new Intent(this, GroupIncomingCallScreen.class);             /*intent.putExtra("location", location);             intent.putExtra("longitude", longitude);             intent.putExtra("latitude", latitude);*/             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);             startActivity(intent);         }         else         {             Intent intent = new Intent(this, GroupCallScreenActivity.class);             /*intent.putExtra("location", location);             intent.putExtra("longitude", longitude);             intent.putExtra("latitude", latitude);*/             intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);             startActivity(intent);         }     }      @Override     public int onStartCommand(Intent intent, int flags, int startId) {          //this.intent = intent;          if(intent != null && intent.getAction() != null)         {             if (intent.getAction().equals(ACTION_RESTORE_ACTIVITY))             {                 if(mCall.getDirection() == CallDirection.INCOMING)                 {                      /*location = intent.getStringExtra("location");                     longitude = intent.getStringExtra("longitde");                     latitude = intent.getStringExtra("latitude");*/                      if(mCall.getState().toString().equals(CallState.INITIATING.toString()))                     {                         Intent activity = new Intent(this, GroupIncomingCallScreen.class);                         /*activity.putExtra("location", location);                         activity.putExtra("longitude", longitude);                         activity.putExtra("latitude", latitude);*/                         activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);                         startActivity(activity);                         return super.onStartCommand(intent, flags, startId);                     }                 }                  Intent activity = new Intent(this, GroupCallScreenActivity.class);                 /*activity.putExtra("location", location);                 activity.putExtra("longitude", longitude);                 activity.putExtra("latitude", latitude);*/                 activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);                 startActivity(activity);             }         }         return super.onStartCommand(intent, flags, startId);     }      private void showNotification(){          Intent intent = new Intent(this, GroupCallService.class);         intent.setAction(ACTION_RESTORE_ACTIVITY);         PendingIntent pendIntent = PendingIntent.getService(this, 0, intent, 0);          NotificationCompat.Builder builder = new NotificationCompat.Builder(this);         String name = ChatDatabaseHandler.getInstance(this).getFriendName(mCall.getRemoteUserId());          if(name == null)             builder.setContentTitle("Call is in progress");         else             builder.setContentTitle("Call is in progress with " + name);          builder.setContentText("Tap to to get back to Call Screen");         builder.setSmallIcon(R.drawable.ic_stat_name);         builder.setColor(getResources().getColor(R.color.sexy_green));         builder.setContentIntent(pendIntent);         builder.setOngoing(true);          startForeground(50, builder.build());     }      @Override     public void onDestroy() {         super.onDestroy();          stopForeground(true);     }      @Override     public IBinder onBind(Intent intent) {         return mServiceInterface;     }      private void answer() {         mAudioPlayer.stopRingtone();         mCall.answer();          LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_FINISH_CALL_ACTIVITY));          Intent intent = new Intent(this, GroupCallScreenActivity.class);         /*intent.putExtra("location", location);         intent.putExtra("longitude", longitude);         intent.putExtra("latitude", latitude);*/         intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);         startActivity(intent);     }      private void decline() {          mAudioPlayer.stopRingtone();         mCall.hangup();          LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_FINISH_CALL_ACTIVITY));     }      private void endCall() {          mAudioPlayer.stopProgressTone();         mCall.hangup();         stopSelf();         LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_FINISH_CALL_ACTIVITY));     }      @Override     public void onCallEnded(Call call) {         CallEndCause cause = call.getDetails().getEndCause();         Log.d(LOG_TAG, "Call ended, cause: " + cause.toString());          if(mCall.getDirection() == CallDirection.INCOMING)         {             mAudioPlayer.stopRingtone();             stopSelf();             LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(ACTION_FINISH_CALL_ACTIVITY));         }         else         {             mAudioPlayer.stopProgressTone();             Utils.Log("Call ended. Reason: " + cause.toString());              Intent intent = new Intent(ACTION_CHANGE_AUDIO_STREAM);             intent.putExtra("STREAM_TYPE", AudioManager.USE_DEFAULT_STREAM_TYPE);             LocalBroadcastManager.getInstance(this).sendBroadcast(intent);              endCall();         }     }      @Override     public void onCallEstablished(Call call) {         Log.d(LOG_TAG, "Call established");          mCallStart = System.currentTimeMillis();          if(mCall.getDirection() == CallDirection.OUTGOING)         {             mAudioPlayer.stopProgressTone();              Intent intent = new Intent(ACTION_UPDATE_CALL_STATE);             intent.putExtra("STATE", call.getState().toString());             LocalBroadcastManager.getInstance(this).sendBroadcast(intent);              intent = new Intent(ACTION_CHANGE_AUDIO_STREAM);             intent.putExtra("STREAM_TYPE", AudioManager.STREAM_VOICE_CALL);             LocalBroadcastManager.getInstance(this).sendBroadcast(intent);         }         else if(mCall.getDirection() == CallDirection.INCOMING)         {             Intent intent = new Intent(ACTION_UPDATE_CALL_STATE);             intent.putExtra("STATE", call.getState().toString());             LocalBroadcastManager.getInstance(this).sendBroadcast(intent);              intent = new Intent(ACTION_CHANGE_AUDIO_STREAM);             intent.putExtra("STREAM_TYPE", AudioManager.STREAM_VOICE_CALL);             LocalBroadcastManager.getInstance(this).sendBroadcast(intent);         }     }      @Override     public void onCallProgressing(Call call) {         Log.d(LOG_TAG, "Call progressing");          if(mCall.getDirection() == CallDirection.OUTGOING)         {             mAudioPlayer.playProgressTone();         }     } } 

and this is the error from the log:

10-25 19:12:11.671: E/AndroidRuntime(28545): FATAL EXCEPTION: main 10-25 19:12:11.671: E/AndroidRuntime(28545): Process: com.galsa.example, PID: 28545 10-25 19:12:11.671: E/AndroidRuntime(28545): java.lang.RuntimeException: Unable to create service com.galsa.example.call.GroupCallService: java.lang.NullPointerException: Attempt to invoke interface method 'void com.sinch.android.rtc.calling.Call.addCallListener(com.sinch.android.rtc.calling.CallListener)' on a null object reference 10-25 19:12:11.671: E/AndroidRuntime(28545):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3661) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at android.app.ActivityThread.access$2000(ActivityThread.java:198) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1759) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at android.os.Handler.dispatchMessage(Handler.java:102) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at android.os.Looper.loop(Looper.java:145) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at android.app.ActivityThread.main(ActivityThread.java:6837) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at java.lang.reflect.Method.invoke(Native Method) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at java.lang.reflect.Method.invoke(Method.java:372) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 10-25 19:12:11.671: E/AndroidRuntime(28545): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void com.sinch.android.rtc.calling.Call.addCallListener(com.sinch.android.rtc.calling.CallListener)' on a null object reference 10-25 19:12:11.671: E/AndroidRuntime(28545):    at com.galsa.example.call.GroupCallService.onCreate(GroupCallService.java:102) 10-25 19:12:11.671: E/AndroidRuntime(28545):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3651) 

Note: this method works with app-to-app call and video call.

回答1:

It looks like you have not hooked up the call listeners, call.addCallListener(...), see more here: https://www.sinch.com/docs/voice/android/.

And check here https://www.sinch.com/tutorials/android-app-to-app-voip-tutorial/ for code. It for person to person calling but its the exact same concept with listeners.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!