flutter-webrtc / callkeep

iOS CallKit and Android ConnectionService for Flutter
MIT License
131 stars 142 forks source link

Hi, When the background fcm arrives to device, it opens the apps home screen, not showing incoming call at all #59

Open muhammedrashidm opened 3 years ago

muhammedrashidm commented 3 years ago

I/flutter ( 9852): backgroundMessage: message => {data: {caller_id: +8618612345678, type: VIDEO_CALL, uuid: xxxxx-xxxxx-xxxxx-xxxxx, has_video: true, caller_id_type: number, caller_name: hello}} D/RNCK:VoiceConnectionService( 9852): setAvailable: false E/MethodChannel#FlutterCallKeep.Method( 9852): Failed to handle method call E/MethodChannel#FlutterCallKeep.Method( 9852): java.lang.SecurityException: PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission. E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.Parcel.createExceptionOrNull(Parcel.java:2373) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.Parcel.createException(Parcel.java:2357) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.Parcel.readException(Parcel.java:2340) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.Parcel.readException(Parcel.java:2282) E/MethodChannel#FlutterCallKeep.Method( 9852): at com.android.internal.telecom.ITelecomService$Stub$Proxy.registerPhoneAccount(ITelecomService.java:1972) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.telecom.TelecomManager.registerPhoneAccount(TelecomManager.java:1317) E/MethodChannel#FlutterCallKeep.Method( 9852): at io.wazo.callkeep.CallKeepModule.registerPhoneAccount(CallKeepModule.java:599) E/MethodChannel#FlutterCallKeep.Method( 9852): at io.wazo.callkeep.CallKeepModule.registerPhoneAccount(CallKeepModule.java:233) E/MethodChannel#FlutterCallKeep.Method( 9852): at io.wazo.callkeep.CallKeepModule.setup(CallKeepModule.java:221) E/MethodChannel#FlutterCallKeep.Method( 9852): at io.wazo.callkeep.CallKeepModule.HandleMethodCall(CallKeepModule.java:108) E/MethodChannel#FlutterCallKeep.Method( 9852): at com.github.cloudwebrtc.flutter_callkeep.FlutterCallkeepPlugin.onMethodCall(FlutterCallkeepPlugin.java:69) E/MethodChannel#FlutterCallKeep.Method( 9852): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233) E/MethodChannel#FlutterCallKeep.Method( 9852): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85) E/MethodChannel#FlutterCallKeep.Method( 9852): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:818) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.MessageQueue.nativePollOnce(Native Method) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.MessageQueue.next(MessageQueue.java:335) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.Looper.loop(Looper.java:183) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.app.ActivityThread.main(ActivityThread.java:7656) E/MethodChannel#FlutterCallKeep.Method( 9852): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#FlutterCallKeep.Method( 9852): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/MethodChannel#FlutterCallKeep.Method( 9852): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) E/MethodChannel#FlutterCallKeep.Method( 9852): Caused by: android.os.RemoteException: Remote stack trace: E/MethodChannel#FlutterCallKeep.Method( 9852): at com.android.server.telecom.PhoneAccountRegistrar.registerPhoneAccount(PhoneAccountRegistrar.java:776) E/MethodChannel#FlutterCallKeep.Method( 9852): at com.android.server.telecom.TelecomServiceImpl$1.registerPhoneAccount(TelecomServiceImpl.java:536) E/MethodChannel#FlutterCallKeep.Method( 9852): at com.android.internal.telecom.ITelecomService$Stub.onTransact(ITelecomService.java:922) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.Binder.execTransactInternal(Binder.java:1154) E/MethodChannel#FlutterCallKeep.Method( 9852): at android.os.Binder.execTransact(Binder.java:1123) E/MethodChannel#FlutterCallKeep.Method( 9852): D/FLT:CallKeepModule( 9852): backToForeground, app isOpened ?true E/flutter ( 9852): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(error, PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission., null, java.lang.SecurityException: PhoneAccount connection service requires BIND_TELECOM_CONNECTION_SERVICE permission.

rekonvald commented 3 years ago

Hi! Try to add

    <uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />

and

        <service android:name="io.wazo.callkeep.VoiceConnectionService"
            android:label="Wazo"
            android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
            <intent-filter>
                <action android:name="android.telecom.ConnectionService" />
            </intent-filter>
        </service>

to AndroidManifest

muhammedrashidm commented 3 years ago

Thank you reko . But I've already added the permission. And there is two problems, 1 it says the telecom binding permission is for system app only, And I've added android name as io. flutter. Wazo.....

As said in pub.dev doc. Still it just opens the app and not showing the accept screen

muhammedrashidm commented 3 years ago

manifest error call keep

muhammedrashidm commented 3 years ago

it says the io.wazo.callkeep.voiceCo.... class dose not available

xyzbilal commented 3 years ago

I assume you added Application.java according to firebase_messaging instructions. Because background message is a different isolate and runs as I service, you should make modifications in android side.

first modify Application. java according to your project. I share mine as example

package yourpackename;

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;
import io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin;
import com.github.cloudwebrtc.flutter_callkeep.FlutterCallkeepPlugin;
import io.flutter.plugins.pathprovider.PathProviderPlugin;
import fr.g123k.flutterappbadger.FlutterAppBadgerPlugin;
public class Application extends FlutterApplication implements PluginRegistrantCallback {

    @Override

    public void onCreate() {
        super.onCreate();
        FlutterFirebaseMessagingService.setPluginRegistrant(this);
    }

    @Override
    public void registerWith(PluginRegistry pluginRegistry) {

        FirebaseMessagingPlugin.registerWith(pluginRegistry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
        FlutterCallkeepPlugin.registerWith(pluginRegistry.registrarFor("com.github.cloudwebrtc.flutter_callkeep"));
        PathProviderPlugin.registerWith(pluginRegistry.registrarFor("io.flutter.plugins.pathprovider"));
        FlutterAppBadgerPlugin.registerWith(pluginRegistry.registrarFor("fr.g123k.flutterappbadger"));
    }
}

add firebase dependency to /android/app/build.graddle

dependencies {

    implementation 'com.google.firebase:firebase-messaging:21.0.1'

}

check if belov permissons are added to AndroidManifest. xml

  <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
    <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

    <uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE"/>
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />

ıt must work properly then

muhammedrashidm commented 3 years ago

application

this is application.java . as you see most of the imports including the callkeep are not used, if i am wrong, i am a beginer. why there is errors and still firebase messaging works basically. and the call keep is not working

muhammedrashidm commented 3 years ago

![Uploading manifest error call keep 2.PNG…]()

muhammedrashidm commented 3 years ago

error of call keep this is the what i am getting after running it. the printed "Display incoming call Now " if from a function in call keep setup, in th official example,

muhammedrashidm commented 3 years ago

Wen app is in background, it opens the home screen, and in run tab:-

I/flutter ( 8168): {notification: {title: null, body: null}, data: {caller_id: +8618612345678, type: VIDEO_CALL, uuid: xxxxx-xxxxx-xxxxx-xxxxx, has_video: true, caller_id_type: number, caller_name: hello}} I/flutter ( 8168): Display incoming call now W/com.tapfy.me( 8168): Reducing the number of considered missed Gc histogram windows from 127 to 100 W/com.tapfy.me( 8168): Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (greylist,core-platform-api, linking, allowed) I/flutter ( 8168): backgroundMessage: message => {data: {caller_id: +8618612345678, type: VIDEO_CALL, uuid: xxxxx-xxxxx-xxxxx-xxxxx, has_video: true, caller_id_type: number, caller_name: hello}} I/flutter ( 8168): backgroundMessage: displayIncomingCall (+8618612345678) D/RNCK:VoiceConnectionService( 8168): setAvailable: false D/RNCK:VoiceConnectionService( 8168): setAvailable: true D/FLT:CallKeepModule( 8168): backToForeground, app isOpened ?true D/EGL_emulation( 8168): eglCreateContext: 0xece601b0: maj 2 min 0 rcv 2 D/EGL_emulation( 8168): eglCreateContext: 0xece5ee70: maj 2 min 0 rcv 2 D/HostConnection( 8168): HostConnection::get() New Host Connection established 0xece6a4e0, tid 8750 D/HostConnection( 8168): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 D/EGL_emulation( 8168): eglMakeCurrent: 0xece5ee70: ver 2 0 (tinfo 0xaeeb50f0) (first time) D/RNCK:VoiceConnectionService( 8168): setAvailable: false D/RNCK:VoiceConnectionService( 8168): setAvailable: true D/HostConnection( 8168): HostConnection::get() New Host Connection established 0xece421c0, tid 8749 D/HostConnection( 8168): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_async_unmap_buffer ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_async_frame_commands ANDROID_EMU_gles_max_version_2 D/EGL_emulation( 8168): eglMakeCurrent: 0xece601b0: ver 2 0 (tinfo 0xed1bf790) (first time) D/EGL_emulation( 8168): eglCreateContext: 0xece67d80: maj 2 min 0 rcv 2 D/RNCK:VoiceConnectionService( 8168): setAvailable: false D/RNCK:VoiceConnectionService( 8168): setAvailable: true I/flutter ( 8168): [FCM] token => ctg2RpCKRf6_RsGO4Pxr2B:APA91bHPWNr5-FGZ-0vEI_3BfYkU4IVXFAPSyDeE_dBKGqOjwepFhdRdDZRTW33lhpirXHnaFpkdaQFtpThygUJh8aU6H6iuRMtpz8mzQ7odqmbHnBq0B2Z1CVT1ha13lr4DAMrDlt9j D/RNCK:VoiceConnectionService( 8168): setAvailable: false D/RNCK:VoiceConnectionService( 8168): setAvailable: true

ghenry commented 3 years ago

add firebase dependency to /android/app/build.graddle


dependencies {

    implementation 'com.google.firebase:firebase-messaging:21.0.1'

}

You can do this now so keep up to date with versions:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    // As per https://firebase.google.com/docs/cloud-messaging/android/client
    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:26.7.0')

    // Declare the dependencies for the Firebase Cloud Messaging and Analytics libraries
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-messaging'
    implementation 'com.google.firebase:firebase-analytics'
}
rekonvald commented 3 years ago

Hi! Have you solved issue?

muhammedrashidm commented 3 years ago

Hi! Have you solved issue?

Not yet, The problem is the myBGMH function is on another Thread, Not in the main Flutter Activity. Do You Have any updates?

shreyansh2211 commented 3 years ago

I am also facing same issue, have anyone found the solution?

ScottLee97 commented 3 years ago

Hi! Try to add

 <uses-permission android:name="android.permission.BIND_TELECOM_CONNECTION_SERVICE" />
 <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
 <uses-permission android:name="android.permission.READ_PHONE_STATE" />
 <uses-permission android:name="android.permission.CALL_PHONE" />
 <uses-permission android:name="android.permission.RECORD_AUDIO" />

and

        <service android:name="io.wazo.callkeep.VoiceConnectionService"
            android:label="Wazo"
            android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE">
            <intent-filter>
                <action android:name="android.telecom.ConnectionService" />
            </intent-filter>
        </service>

to AndroidManifest

I tried @rekonvald solution and it worked. Thanks!

There are some error messages like

Class referenced in the manifest, io.wazo.callkeep.VoiceConnectionService, was not found in the project or the libraries

Permission is only granted to system apps

But I simply ignored them and close my app and restarted it. It worked thereafter.

Remember to do the callsetup stated in the callkeep documentation too.

miracle101000 commented 2 years ago

@muhammedrashidm Hey bro, so I had the same issue as you.

I think you should make sure you add this somewhere in your app:

   final bool hasPhoneAccount = await _callKeep.hasPhoneAccount();
    if (!hasPhoneAccount) {
      await _callKeep.hasDefaultPhoneAccount(context, <String, dynamic>{
        'alertTitle': 'Permissions required',
        'alertDescription':
            'APP needs to access this permission to accept phone calls',
        'cancelButton': 'Cancel',
        'okButton': 'ok',
        'foregroundService': {
         'channelId': 'com.company.my',
          'channelName': 'Foreground service for my app',
          'notificationTitle': 'My app is running on background',
          'notificationIcon': 'Path to the resource icon of the notification',
        },
      })
    }

After adding the necessary permissions in your manifest file as stated above