Giter VIP home page Giter VIP logo

Comments (11)

k00na avatar k00na commented on August 29, 2024 2

Hey!
Thanks for filing in your issue 👍

Do you have this issue both on Android and iOS? We were also having issues with using this on Android.

So right now on Android we're not using displayIncomingCall() at all... we're using displayCustomIncomingCall() instead. Also if the app is running in foreground while a call comes in, we're using MethodChannel to call the native android IncomingCallActivity.

Take a look here:

Future<void> displayIncomingCall(String handle) async {
    if (Platform.isIOS) {
      // iOS uses displayIncomingCall() 
      CallKit.displayIncomingCall(this.uuid, handle: handle, hasVideo: this.isVideoCall);
    } else {
      
      Map<String, dynamic> callData = {
        'yourAppId.yourAppId.CALL_ID': id,
        'yourAppId.yourAppId.CALL_UUID': this.uuid,
        'yourAppId.yourAppId.CALLER_HANDLE': handle,
      };

      if (DoneLifeCycleState.instance.isAppInForeground) {
        // if app in foreground, display the android activity for answering calls
        displayAndroidIncomingCallActivity(callData);
      } else {
        // display call notification if in background
        await _displayIncomingCallNotification(callData);
      }
    }
  }

Calling method channel to display Android activity:

Future<void> displayAndroidIncomingCallActivity(Map<String, dynamic> callData) async {
    MethodChannel _channel = MethodChannel('your.channel.id');
    String result = await _channel.invokeMethod('yourNativeAndroidMethodName', callData);
  }

Displays the "incoming call notification" if app is running in background or displays full screen activity if app not running.
Note that this function is also triggered when app is not running and the phone is locked, giving the user the expected UX for answering calls - a full screen activity on Android.

Future<void> _displayIncomingCallNotification(Map<String, dynamic> callData) async {
    String incomingCallUsername = callData['your.app.id.CALLER_HANDLE'];
  displayIncomingCallNotification()
    await CallKeep.displayCustomIncomingCall(
      'your.app.id',
      'YourCustomAndroidActivityForIncomingCalls',
      icon: 'notification_icon',
      contentTitle: S().callNotificationTitle(incomingCallUsername),
      answerText: S().callAnswer,
      declineText: S().callDecline,
      extra: callData,
    );
  }

from flutter_callkeep.

mlukovic avatar mlukovic commented on August 29, 2024 2

Wow! You just replied immediately! Thanks for that!

I will try to make it work and also try to contribute and optionally show the Notification.

Thanks a lot!

from flutter_callkeep.

mlukovic avatar mlukovic commented on August 29, 2024 1

Hey @k00na,

Tnx for a great example. Can you explain the logic how is expected to handle the call after you open Android Native Activity?

from flutter_callkeep.

k00na avatar k00na commented on August 29, 2024 1

Sure thing!

I've added a wiki page real quick, you can take a look at it here. Hope it helps 🤞

from flutter_callkeep.

k00na avatar k00na commented on August 29, 2024 1

No prob!

To hide the notification, I guess you'd have to make your own fork of the library where you'd override the behaviour in CallKeep.kt for the displayCustomIncomingCall() function, moving away all the logic for displaying the notification. But it would be even more awesome if you could contribute to this project by making a PR with your modifications here on GitHub and become a contributer 😉

Also, here's the AndroidManifest code (some lines are irrelevant to the calls feature):


<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.app.id">

    <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.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.WRITE_CALENDAR" />

    <application android:name=".Application" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:launchMode="singleTop" android:requestLegacyExternalStorage="true">

        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
        <meta-data android:name='com.facebook.sdk.AutoLogAppEventsEnabled' android:value='false' />
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
        <meta-data android:name="com.google.android.geo.API_KEY" android:value="yourKeyValue" />
        <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:value="true" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

        <activity android:name=".IncomingCallActivity" android:exported="true" android:showOnLockScreen="true" />
    </application>
</manifest>

from flutter_callkeep.

mlukovic avatar mlukovic commented on August 29, 2024

Thank you so much @k00na for helping out immediately. I really appreciate sharing your code for IncomingCallActivity.

I am able now to start the custom activity using: CallKeep.displayCustomIncomingCall()
But when I do that I am getting custom Notification on top of the screen for Accepting or Declining the call.
But my goal would be to actually directly show CustomIncomingCallActivity without notification. Is that possible with CallKeep?
Also, I would like to show it in all scenarios: When the App is killed, the phone is locked or the app is in the background or foreground.
If it's possible can you give me some guidance about what I need to set also in Android Manifest?

btw. I am testing on Android 10 version.

Thank you so much!

from flutter_callkeep.

mlukovic avatar mlukovic commented on August 29, 2024

Just one quick question. How currently you're handling scenarios if the phone is locked?

from flutter_callkeep.

k00na avatar k00na commented on August 29, 2024

We display the full screen native android activity including the ringing sound in all scenarios when phone is locked (app in foreground, background or not running at all).

from flutter_callkeep.

prozaklob avatar prozaklob commented on August 29, 2024

We display the full screen native android activity including the ringing sound in all scenarios when phone is locked (app in foreground, background or not running at all).

could you show a small example of this? I'm a newbie and have been unable to run in the background.

#19 (comment)

from flutter_callkeep.

hanleiZoro avatar hanleiZoro commented on August 29, 2024

I'm sorry, VoIP is banned in China. I'll close the question

from flutter_callkeep.

prozaklob avatar prozaklob commented on August 29, 2024

I'm sorry, VoIP is banned in China. I'll close the question

bt not banned on belarus )))) help other dev's,bro ))

from flutter_callkeep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.