flutter-webrtc / callkeep

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

Android setup issue #67

Open rekonvald opened 3 years ago

rekonvald commented 3 years ago

Hi! I am facing such issue: I use FCM for handling background messages and I try to init callkeep into my backgroundMessageHandler as it is described into example, but when I call _callKeep.setup i get [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(E_ACTIVITY_DOES_NOT_EXIST, Activity doesn't exist, null, null) E/flutter (21173): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:581:7)

I added all necessary permissions into AndroidManifest.xml:

<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.INTERNET"/>
<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" />

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

<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" />
<!-- These require runtime permissions on M -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />

I also updated my activity: `import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.os.Build import io.flutter.app.FlutterApplication import io.flutter.plugin.common.PluginRegistry import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback import io.flutter.view.FlutterMain import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin import com.github.cloudwebrtc.flutter_callkeep.FlutterCallkeepPlugin import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin

class Application : FlutterApplication(), PluginRegistrantCallback { override fun onCreate() { super.onCreate() this.createChannel() FlutterFirebaseMessagingBackgroundService.setPluginRegistrant(this); FlutterMain.startInitialization(this) }

override fun registerWith(registry: PluginRegistry) {
    FirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"));
    io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin.registerWith(registry.registrarFor("io.flutter.plugins.firebase.messaging.FirebaseMessagingPlugin"));
    FlutterCallkeepPlugin.registerWith(registry?.registrarFor("com.github.cloudwebrtc.flutter_callkeep"));
    FlutterLocalNotificationsPlugin.registerWith(registry!!.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"));
}

private fun createChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // Create the NotificationChannel
        val name = getString(R.string.default_notification_channel_id)
        val channel = NotificationChannel(name, "default", NotificationManager.IMPORTANCE_HIGH)
        val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as? NotificationManager
        notificationManager?.createNotificationChannel(channel)
    }
}

}`

I would great maybe to skip _checkPhoneAccountPermission, I just want to use it for displaying incoming call window when app is in background/locked or terminated.

BTW: when I use _callKeep.backToForeground() it works for Android 9, but doesn't for Android 11

abdiwankenobi commented 3 years ago

Have you fixed this issue? I have the exact same problem.

rekonvald commented 3 years ago

Hi! No, I use https://pub.dev/packages/connectycube_flutter_call_kit

Alijaaan commented 3 years ago

Same issue here ...

samerkh commented 3 years ago

any solution yet?

janhelwich commented 3 years ago

I had the same issue. After some log-analysis I found out that in my case the phone account initialzation was done at a time where it couldn't do its job. Specifically the phone account check:


    bool hasPhoneAccount = await callKeep.hasPhoneAccount();
    if (!hasPhoneAccount) {
      hasPhoneAccount = await callKeep.hasDefaultPhoneAccount(context, callSetup["android"]);
    }

After putting it in the initialising of the first screen the user actually sees it worked for me.

rlee1990 commented 3 years ago

@janhelwich How do you get the setting to stay I added the same code but it comes up on each app launch.

janhelwich commented 3 years ago

Hey @rlee1990 , honestly i think i didn't do anything more. It just does stay.