Skip to content

Commit

Permalink
feat: answer from notification killed state
Browse files Browse the repository at this point in the history
  • Loading branch information
diegog-sf committed Oct 23, 2021
1 parent 8de300c commit e3a45f2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 44 deletions.
11 changes: 1 addition & 10 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,7 @@ dependencies {
implementation platform('com.google.firebase:firebase-bom:26.0.0')
implementation 'com.twilio:voice-android:5.8.0'
implementation 'com.google.firebase:firebase-messaging'
// implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
// implementation 'com.google.android.material:material:1.0.0'
// implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
// implementation 'androidx.media:media:1.0.0'
// androidTestImplementation 'androidx.test.ext:junit:1.1.1'
// androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// implementation 'tw.geothings.rekotlin:rekotlin:0.1.0-SNAPSHOT'
// implementation 'io.reactivex.rxjava2:rxkotlin:2.4.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
}

Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ private void handleIncomingCallIntent(Intent intent) {
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
Log.d(TAG, "onNewIntent-");
if (intent != null && intent.getAction() != null) {
Log.d(TAG, "onNewIntent-");
Log.d(TAG, intent.getAction());
switch (intent.getAction()) {
case Constants.ACTION_CANCEL_CALL:
Expand Down Expand Up @@ -298,7 +298,7 @@ public void onReceive(Context context, Intent intent) {
}

private void registerReceiver() {
Log.d(TAG, "Registering receiver");
Log.d(TAG, "Registering answerJavaActivity receiver");
if (!isReceiverRegistered) {
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Constants.ACTION_TOGGLE_MUTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
break;
case Constants.ACTION_ACCEPT:
int origin = intent.getIntExtra(Constants.ACCEPT_CALL_ORIGIN, 0);
Log.d(TAG, "onStartCommand-ActionAccept $origin");
Log.d(TAG, "onStartCommand-ActionAccept" + origin);
accept(callInvite, notificationId, origin);
break;
case Constants.ACTION_REJECT:
Expand Down Expand Up @@ -89,13 +89,15 @@ private Notification createNotification(CallInvite callInvite, int notificationI
String caller = preferences.getString(fromId, preferences.getString("defaultCaller", "Unknown caller"));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Log.i(TAG, "building notification for new phones");
return buildNotification(getApplicationName(context), getString(R.string.new_call, caller),
pendingIntent,
extras,
callInvite,
notificationId,
createChannel(channelImportance));
} else {
Log.i(TAG, "building notification for older phones");

return new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_call_end_white_24dp)
Expand Down Expand Up @@ -191,14 +193,29 @@ private void accept(CallInvite callInvite, int notificationId, int origin) {
endForeground();
Log.i(TAG, "accept call invite!");
SoundPoolManager.getInstance(this).stopRinging();
Intent activeCallIntent = new Intent();

Intent activeCallIntent;
if (origin == 0 && !isAppVisible()) {
Log.i(TAG, "Creating answerJavaActivity intent");
activeCallIntent = new Intent(this, AnswerJavaActivity.class);
} else {
Log.i(TAG, "Creating answer broadcast intent");
activeCallIntent = new Intent();
}

activeCallIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
activeCallIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activeCallIntent.putExtra(Constants.INCOMING_CALL_INVITE, callInvite);
activeCallIntent.putExtra(Constants.INCOMING_CALL_NOTIFICATION_ID, notificationId);
activeCallIntent.putExtra(Constants.ACCEPT_CALL_ORIGIN, origin);
activeCallIntent.setAction(Constants.ACTION_ACCEPT);
LocalBroadcastManager.getInstance(this).sendBroadcast(activeCallIntent);
if (origin == 0 && !isAppVisible()) {
startActivity(activeCallIntent);
Log.i(TAG, "starting activity");
} else {
LocalBroadcastManager.getInstance(this).sendBroadcast(activeCallIntent);
Log.i(TAG, "sending broadcast intent");
}
}

private void reject(CallInvite callInvite) {
Expand Down
38 changes: 19 additions & 19 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand All @@ -42,21 +42,21 @@ packages:
name: cloud_functions
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "3.0.5"
cloud_functions_platform_interface:
dependency: transitive
description:
name: cloud_functions_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.1"
version: "5.0.12"
cloud_functions_web:
dependency: transitive
description:
name: cloud_functions_web
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.3"
version: "4.0.14"
collection:
dependency: transitive
description:
Expand All @@ -70,7 +70,7 @@ packages:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "1.0.3"
fake_async:
dependency: transitive
description:
Expand All @@ -84,63 +84,63 @@ packages:
name: firebase_auth
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "3.1.4"
firebase_auth_platform_interface:
dependency: transitive
description:
name: firebase_auth_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.0"
version: "6.1.2"
firebase_auth_web:
dependency: transitive
description:
name: firebase_auth_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.6"
version: "3.1.3"
firebase_core:
dependency: "direct main"
description:
name: firebase_core
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
version: "1.8.0"
firebase_core_platform_interface:
dependency: transitive
description:
name: firebase_core_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.0"
version: "4.0.1"
firebase_core_web:
dependency: transitive
description:
name: firebase_core_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
version: "1.1.0"
firebase_messaging:
dependency: "direct main"
description:
name: firebase_messaging
url: "https://pub.dartlang.org"
source: hosted
version: "9.1.1"
version: "10.0.9"
firebase_messaging_platform_interface:
dependency: transitive
description:
name: firebase_messaging_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
version: "3.0.7"
firebase_messaging_web:
dependency: transitive
description:
name: firebase_messaging_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "2.0.7"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -190,7 +190,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand All @@ -204,7 +204,7 @@ packages:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.0.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -251,7 +251,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.2"
twilio_voice:
dependency: "direct main"
description:
Expand All @@ -274,5 +274,5 @@ packages:
source: hosted
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
dart: ">=2.14.0 <3.0.0"
flutter: ">=1.20.0"
12 changes: 6 additions & 6 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ description: Demonstrates how to use the twilio_voice plugin.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.14.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

firebase_core: ^1.0.3
firebase_messaging: ^9.1.1
cloud_functions: ^1.0.3
firebase_auth: ^1.1.0
firebase_core: ^1.8.0
firebase_messaging: ^10.0.9
cloud_functions: ^3.0.5
firebase_auth: ^3.1.4

twilio_voice:
# When depending on this package from a real application you should use:
Expand All @@ -27,7 +27,7 @@ dependencies:

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
cupertino_icons: ^1.0.3

dev_dependencies:
flutter_test:
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.8.1"
boolean_selector:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
clock:
dependency: transitive
description:
Expand Down Expand Up @@ -73,7 +73,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.7.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -127,7 +127,7 @@ packages:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.2"
typed_data:
dependency: transitive
description:
Expand Down

0 comments on commit e3a45f2

Please sign in to comment.