我正在尝试在Android中使用sinch音频和视频通话,但问题是如何检查来电是音频还是视频。我正在为此目的使用共享偏好。视频通话视频通话在两侧都很好,而当来电是另一侧的音频视频来电活动而不是其他用户电话中的音频。任何帮助都会得到赞赏。
public class SinchService extends Service {
//set the shared preferences
private SharedPreferences mPickSharedPrefs;
private SharedPreferences.Editor mPickSharedPrefsEditor;
private static final String APP_KEY = "*******************";
private static final String APP_SECRET = "****************";
private static final String ENVIRONMENT = "sandbox.sinch.com";
public static final String CALL_ID = "CALL_ID";
static final String TAG = SinchService.class.getSimpleName();
private SinchServiceInterface mSinchServiceInterface = new SinchServiceInterface();
private SinchClient mSinchClient;
private String mUserId;
private StartFailedListener mListener;
@Override
public void onCreate() {
super.onCreate();
mPickSharedPrefs = getSharedPreferences("mPickSharedPrefs", Context.MODE_PRIVATE);
mPickSharedPrefsEditor=mPickSharedPrefs.edit();
}
@Override
public void onDestroy() {
if (mSinchClient != null && mSinchClient.isStarted()) {
mSinchClient.terminate();
}
super.onDestroy();
}
private void start(String userName) {
if (mSinchClient == null) {
mUserId = userName;
mSinchClient = Sinch.getSinchClientBuilder().context(getApplicationContext()).userId(userName)
.applicationKey(APP_KEY)
.applicationSecret(APP_SECRET)
.environmentHost(ENVIRONMENT).build();
mSinchClient.setSupportCalling(true);
mSinchClient.startListeningOnActiveConnection();
mSinchClient.addSinchClientListener(new MySinchClientListener());
// Permission READ_PHONE_STATE is needed to respect native calls.
mSinchClient.getCallClient().setRespectNativeCalls(false);
mSinchClient.getCallClient().addCallClientListener(new SinchCallClientListener());
mSinchClient.start();
}
}
private void stop() {
if (mSinchClient != null) {
mSinchClient.terminate();
mSinchClient = null;
}
}
private boolean isStarted() {
return (mSinchClient != null && mSinchClient.isStarted());
}
@Override
public IBinder onBind(Intent intent) {
return mSinchServiceInterface;
}
public class SinchServiceInterface extends Binder {
public Call callUserVideo(String userId) {
// mPickSharedPrefsEditor=mPickSharedPrefs.edit();
mPickSharedPrefsEditor.putString("call_status","1");
mPickSharedPrefsEditor.commit();
return mSinchClient.getCallClient().callUserVideo(userId);
}
public Call callPhoneNumber(String phoneNumber) {
return mSinchClient.getCallClient().callPhoneNumber(phoneNumber);
}
public Call callUser(String userId) {
// mPickSharedPrefsEditor=mPickSharedPrefs.edit();
mPickSharedPrefsEditor.putString("call_status","0");
mPickSharedPrefsEditor.commit();
return mSinchClient.getCallClient().callUser(userId);
}
public String getUserName() {
return mUserId;
}
public boolean isStarted() {
return SinchService.this.isStarted();
}
public void startClient(String userName) {
start(userName);
}
public void stopClient() {
stop();
}
public void setStartListener(StartFailedListener listener) {
mListener = listener;
}
public Call getCall(String callId) {
return mSinchClient.getCallClient().getCall(callId);
}
public VideoController getVideoController() {
if (!isStarted()) {
return null;
}
return mSinchClient.getVideoController();
}
public AudioController getAudioController() {
if (!isStarted()) {
return null;
}
return mSinchClient.getAudioController();
}
}
public interface StartFailedListener {
void onStartFailed(SinchError error);
void onStarted();
}
private class MySinchClientListener implements SinchClientListener {
@Override
public void onClientFailed(SinchClient client, SinchError error) {
if (mListener != null) {
mListener.onStartFailed(error);
}
mSinchClient.terminate();
mSinchClient = null;
}
@Override
public void onClientStarted(SinchClient client) {
Log.d(TAG, "SinchClient started");
if (mListener != null) {
mListener.onStarted();
}
}
@Override
public void onClientStopped(SinchClient client) {
Log.d(TAG, "SinchClient stopped");
}
@Override
public void onLogMessage(int level, String area, String message) {
switch (level) {
case Log.DEBUG:
Log.d(area, message);
break;
case Log.ERROR:
Log.e(area, message);
break;
case Log.INFO:
Log.i(area, message);
break;
case Log.VERBOSE:
Log.v(area, message);
break;
case Log.WARN:
Log.w(area, message);
break;
}
}
@Override
public void onRegistrationCredentialsRequired(SinchClient client,
ClientRegistration clientRegistration) {
}
}
private class SinchCallClientListener implements CallClientListener {
@Override
public void onIncomingCall(CallClient callClient, Call call) {
Log.d(TAG, "Incoming call");
Log.d(TAG,call.getRemoteUserId());
mPickSharedPrefs=getSharedPreferences("mPickSharedPrefs", Context.MODE_PRIVATE);
mPickSharedPrefsEditor=mPickSharedPrefs.edit();
String Check_Call_Status;
Check_Call_Status=mPickSharedPrefs.getString("call_status","");
Log.d(TAG,Check_Call_Status);
if(Check_Call_Status.equals("1")) {
Log.d(TAG,"Video Call");
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivity.class);
intent.putExtra(CALL_ID, call.getCallId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
mPickSharedPrefsEditor.clear();
}
else
if(Check_Call_Status.equals("0"))
{
Log.d(TAG,"Voice Call");
Intent intent = new Intent(SinchService.this, VoiceIncomingCallScreenActivity.class);
intent.putExtra(CALL_ID, call.getCallId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
mPickSharedPrefsEditor.clear();
}
}
}
}
答案 0 :(得分:1)
I did audio and video calling simultaneously using this below code. In SinchService
private class SinchCallClientListener implements CallClientListener {
@Override
public void onIncomingCall(CallClient callClient, Call call) {
if (call.getDetails().isVideoOffered()) {
Log.d(TAG, "Incoming video call");
Intent intent = new Intent(SinchService.this, VideoIncomingCallScreenActivity.class);
intent.putExtra(CALL_ID, call.getCallId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
} else {
Log.d(TAG, "Incoming audio call");
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivity.class);
intent.putExtra(CALL_ID, call.getCallId());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
SinchService.this.startActivity(intent);
}
}
}
答案 1 :(得分:0)
你不能这样做,如果它是一个视频通话你需要回答它的视频,如果它是一个音频通话你需要像音频一样回答它,接收者不能决定。在GA版本中,我们将有可能在您进行视频通话时不打开视频而只打开音频
答案 2 :(得分:0)
您可以使用
进行检查call.getDetails()。isVideoOffered()
在onIncomingCall(){}函数中。如果返回true,则表示它是视频通话,否则是音频。