I am trying to build an app with app to app calling in Android using Sinch.
I have managed to implement push notifications and the incoming call screen displays on an incoming call, but when I press answer, it takes me to the Call Screen Activity but the call just stays in the initiating state. I am calling "call.answer()" and I swear my code for answering is the same as the sample code provided by sinch.
private void answerClicked() {
mAudioPlayer.stopRingtone();
Call call = getSinchServiceInterface().getCall(mCallId);
if (call != null) {
Log.d(TAG, "Answering call");
call.answer();
Log.d("calls", call.getState().toString());
Intent intent = new Intent(this, CallScreenActivity.class);
intent.putExtra(SinchService.CALL_ID, mCallId);
startActivity(intent);
} else {
Log.d(TAG, "call must be null");
finish();
}
}
"Answering call" is shown in the log. Any idea why it wouldn't be properly answering the call?
Related
I have IOS and Android app using sinch video and Audio (App to App ) calling integrated.
isVideoOffered() Bool always gives video irrespective of incoming call.I want to receive audio screen when audio call is called from another app(Android/IOS) and video if video call is initiated from another app(Android/IOS).
Code for Android to differentiate incoming call(video or audio)
public void onIncomingCall(CallClient callClient, Call call) {
if( call.getDetails().isVideoOffered()){
Log.d(TAG, "Incoming call");
Intent intent = new Intent(SinchService.this, IncomingCallScreenActivityVideo.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);
}
}
Code for IOS to differentiate incoming call(video or audio)
#pragma mark - SINCallClientDelegate
- (void)client:(id<SINCallClientDelegate>)client didReceiveIncomingCall:(id<SINCall>)call {
if (call.details.applicationStateWhenReceived == UIApplicationStateActive) {
if([call.details isVideoOffered]) {
[self performSegueWithIdentifier:#"callView" sender:call];
}
else
{
[self performSegueWithIdentifier:#"audioCallView" sender:call];
}
}
else {
[call answer];
}
}
I can confirm that this is a bug and we will fix it for a future beta release.
I suggest using your VideoActivity layouts and classes for handling both the calls because when an audio call is received, the video portions remain hidden in your layout..
Additionally, you can set an icon that can tell you whether you're on Video Call or not.. I mean you can do somethink like.
#Override
public void onVideoTrackAdded(Call call) {
// Display some kind of icon showing it's a video call
isVideo=true;
}
I have a service listening to some events from server.
A service has START_STICKY flag that makes him restart when it's killed by OS.
When service receive an event i have two scenarios.
First, if activity isn't killed i need to send result to local broadcast receiver and update UI.
Second, if it's killed by OS i want to recreate it and send data in bundle.
But i don't know how to recognize that android killed my activity.
onDestroy activity event doesn't come in this situation.
#Override
public void onComplete(CurrentOrdersResponse response) {
if (response == null) {
return;
}
boolean isActivityDestroyed = mPreferences.getBoolean(MainActivity.IS_MAIN_ACTIVITY_DESTROYED_PREF_KEY, false);
if (!isActivityDestroyed)
sendResult(response.getResJSONStr(), CURRENT_ORDERS_ACTION);
else {
Intent intent = new Intent(this, MainActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtras(extras);
startActivity(intent);
}
int resCode = response.getResCode();
Log.i(LOG_TAG, "Service resCode" + " " + resCode);
}
It sounds like you are using LocalBroadcastManager. That's good. Its sendBroadcast() method returns a boolean indicating if a registered receiver was found. You can use that result to determine if your receiving activity (MainActivity) exists and has registered to receive the broadcast.
When your service has an event to send to MainActivity, first try to send the event using sendBroadcast(). If it returns true, your done. If it returns false, the activity is not registered and must be created using startActivity(), with the event passed as an extra, as shown in your posted code.
In my app i am doing one thing that,when the call is disconnected by caller or receiver,one alert dialog should appear with cellphone number.it all works fine but issue is alert dialog is also appearing when i am getting call,but i only want only after disconnection,i don't know what is mistake i am making following is my code..can any one help?
public class MyCallReceiver extends BroadcastReceiver {
private String incomingNumber;
#Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDLE)) {
// This code will execute when the phone has an incoming call
// get the phone number
incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
Intent i = new Intent(context, Disp_Alert_dialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("Number", incomingNumber);
context.startActivity(i);
Toast.makeText(context, "Call from:" +incomingNumber, Toast.LENGTH_LONG).show();
/* String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
Toast.makeText(context, "Call from:" +incomingNumber, Toast.LENGTH_LONG).show();*/
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_IDLE)
|| intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(
TelephonyManager.EXTRA_STATE_OFFHOOK)) {
// This code will execute when the call is disconnected
}
}
You have written your code in wrong place. This code
Intent i = new Intent(context, Disp_Alert_dialog.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra("Number", incomingNumber);
context.startActivity(i);
will be in else..if condition instead of if condition.
You condition is wrong. You are using else block of
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)
It will run whenever call state changes to 'Ideal' or 'off hook' (in outgoing call - when dialed and call is disconnected, in incoming call - when call is picked up and call is disconnected).
If you want to show dialogue only while disconnecting call, use
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDEAL)
and write code in if block
As for number, you cannot get number that way as it is only valid for ringing state.
A work around would be using a ContentObserver on CallLog. Its onChange() will be called whenever there is a change in call log. You can then take number from call log. But you will need to have a part of your application active for this. Use in a Service may be.
Note- In some devices message also comes in call log data. So check if last entry in call log in of call type or not before showing your dialogue
This may help you in using content observer
I am developing an twilio android client which will wait for an incoming call and naviagte to another activity to accept and answer the call.
phone = BasicPhone.getInstance(getApplicationContext());
phone.setuuid(client_name);
phone.setListeners(this, this, this);
phone.login();
Intent intent = new Intent(getBaseContext(), BasicPhoneActivity.class);
if (inDevice != null && inConnection != null) {
intent.removeExtra(Device.EXTRA_DEVICE);
intent.removeExtra(Device.EXTRA_CONNECTION);
startActivity(intent);
}
Can this be acheived ? I am getting null pointer exception with pendingIncomingConnection.setConnectionListener(this);
More info:
When the user launches the app he is currently in Activity "X" and then if there is an incoming call he should be autmatically sent to Activity "Y".
What do I code in Activity X to wait for the incoming call (Via Twilio).
Please help!
I am new to android.
I am implementing one application related to incoming and outgoing call details.
I am getting outgoing call and incoming call details by using brodcast receivers.
The problem is when the incoming call will come the brodcast receiver will rise,
And i make an outgoing call the brodcast receiver raised.
That is fine,but when i click the green button the outgoing call will start,but
i want exact time of answering the call from otherside.
How i get this?
If any one know please help me.
Thanks in advance.
Try using a TelephonyManager
if ((intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL) || (intent
.getAction()
.equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)))) {
String phoneState = intent.getExtras().getString(
TelephonyManager.EXTRA_STATE);
if (intent.getAction().equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
Log.d(TAG, "Outgoing call");
if (TelephonyManager.EXTRA_STATE_OFFHOOK.equals(phoneState)) {
Log.d(TAG, "Incoming call/Outgng call Started");
}
if (TelephonyManager.EXTRA_STATE_IDLE.equals(phoneState)) {
Log.d(TAG,"Call ended");
}
if (TelephonyManager.EXTRA_STATE_RINGING.equals(phoneState)) {
Log.d(TAG,"Call ringing");
}
}
Continuously check when device state is changed from CALL_STATE_IDLE, to CALL_STATEOFFHOOK... It gives the exact time of your call being answered