我正在尝试从我的Android应用程序启动电话会议,但它不起作用,我尝试的是:
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);
和我的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);
}
}
这是我的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();
}
}
}
这是日志中的错误:
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)
注意:此方法适用于应用到应用的通话和视频通话。
答案 0 :(得分:0)
看起来你没有连接呼叫监听器,call.addCallListener(...)
,请点击此处:
https://www.sinch.com/docs/voice/android/
并在此处https://www.sinch.com/tutorials/android-app-to-app-voip-tutorial/查看代码。它适用于人与人之间的呼唤,但与听众完全相同。