cybex-dev / twilio_voice

Flutter Twilio Voice Plugin
https://twilio-voice-web.web.app/
MIT License
40 stars 84 forks source link

I can't answer a call when app is killed #17

Closed nestorsgarzonc closed 1 year ago

nestorsgarzonc commented 3 years ago

Hi, I'm using the demo app. I make the configurations and work the app when is in first plane and second plane but when I close the app I receive the notification and try to answer nothing happen. The app doesn't start and I can't answer the call

MeMoSalem commented 2 years ago

Hello Guys

I had the same issue with Android and I was getting the notification/Widget for incoming call while app was terminated but nothing happens when the user clicks on Answer/Accept

and here what I have done to solve it: 1- I have replaced these three files {"IncomingCallNotificationService.java", "TwilioVoicePlugin.java", "AnswerJavaActivity.java" } from this repo ---> https://github.com/diegogarciar/twilio_voice/tree/master/android/src/main/java/com/twilio/twilio_voice

2- after the first step I have noticed that there is a screen that tries to open but it disappears right away when you try to answer the call while app is terminated "for the first time" so we need to comment out the following code inside file "AnswerJavaActivity.java" in the following method private void acceptCall() { Log.d(TAG, "Accepting call"); Intent acceptIntent = new Intent(this, IncomingCallNotificationService.class); acceptIntent.setAction(Constants.ACTION_ACCEPT); acceptIntent.putExtra(Constants.INCOMING_CALL_INVITE, activeCallInvite); acceptIntent.putExtra(Constants.ACCEPT_CALL_ORIGIN, 0); acceptIntent.putExtra(Constants.INCOMING_CALL_NOTIFICATION_ID, activeCallNotificationId); Log.d(TAG, "Clicked accept startService"); startService(acceptIntent); // if (TwilioVoicePlugin.hasStarted) { // finish(); // } else { Log.d(TAG, "Answering call"); activeCallInvite.accept(this, callListener); notificationManager.cancel(activeCallNotificationId); // } }

3- In the file "TwilioVoicePlugin.java" inside the method "private void handleIncomingCallIntent(Intent intent)" we need to replace this case Constants.ACTION_ACCEPT: int acceptOrigin = intent.getIntExtra(Constants.ACCEPT_CALL_ORIGIN,0); if(acceptOrigin == 0){ Intent answerIntent = new Intent(activity, AnswerJavaActivity.class); answerIntent.setAction(Constants.ACTION_ACCEPT); answerIntent.putExtra(Constants.INCOMING_CALL_NOTIFICATION_ID, activeCallNotificationId); answerIntent.putExtra(Constants.INCOMING_CALL_INVITE, activeCallInvite); answerIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); answerIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); activity.startActivity(answerIntent); }else{ answer(); } break;

with:

case Constants.ACTION_ACCEPT: int acceptOrigin = intent.getIntExtra(Constants.ACCEPT_CALL_ORIGIN,0); answer(); break;

4- Last step inside the file "" to change the value of "TwilioPreferences" String to be like: TwilioPreferences = "com.twilio.twilio_voicePreferences";

instead of

TwilioPreferences = "mx.TwilioPreferences";

Note !!! just to display the correct name of the caller and also this package replaces the divider for clients Ids from "-" to "_" so you might need to change this if your users' ids have this "-" divider. there will be some other alterations in order to show correct way of Notifying the user with the incoming call regarding Android version that I happy to share if the above worked for you

federico-amura-kenility commented 2 years ago

I have the same issue on android. I think the way its implemented on Android is wrong. If the app is closed, the flutter plugin will never been initialized, so the call can't start. I rewrite all the Android part, and its working great for 2 of our apps. Maybe its useful for some of you https://pub.dev/packages/flutter_twilio

diegog-sf commented 2 years ago

you could've created a PR instead :(

federico-amura-kenility commented 2 years ago

i know, but when i wrote this change, i needed the solution ASAP for my company. Making a PR and waiting for approval would take more time than I had available. Maybe someone of you can take my code from the new library and create a PR for this library. I only wrote here to help whoever needs it

bazl-E commented 2 years ago

problem was solved at least for me what i did I downloaded the /root folder again and it worked.

Could you please explain which folder you replaced exactly?

bazl-E commented 2 years ago

I have the same issue on android. I think the way its implemented on Android is wrong. If the app is closed, the flutter plugin will never been initialized, so the call can't start. I rewrite all the Android part, and its working great for 2 of our apps. Maybe its useful for some of you https://pub.dev/packages/flutter_twilio

How could i pass from number to this package ,as my application have multiple from numbers...please explain

cybex-dev commented 1 year ago

@federico-amura-kenility I see in your repo you've already added Android side caller name resolution, including a few enhancements.

I'm busy adding this with somewhat standardized placeholders, feel free to contribute to this - I'll tag you in the feature PR when its in review.

cybex-dev commented 1 year ago

Closing for now.