WebsiteBeaver / CordovaCall

Cordova CallKit & ConnectionService plugin for iOS/Android that displays the native call UI for VOIP apps
MIT License
196 stars 91 forks source link

Call with data notification #107

Closed mozhn closed 3 years ago

mozhn commented 3 years ago

Thanks to the library below, I can display a call acceptance screen for my user while the application is closed. But this is only for ios. I want to do this in Android but I couldn't understand what to do.

https://github.com/mattkhaw/cordova-plugin-callkit

My notification code

const OneSignal = require('onesignal-node');
const client = new OneSignal.Client(
  '***',
  '***'
);

client.createNotification({
  include_player_ids: ['***'],
  content_available: true,
  data: {
    Caller: {
      Username: 'user',
      ConnectionId: 'asddasasd',
    }
  }
});
rgustavsson commented 3 years ago

@mozhn how did you solve your issue with Android?

mozhn commented 3 years ago

@mozhn how did you solve your issue with Android?

My code:

   await axios.default.post('https://fcm.googleapis.com/fcm/send', {
      'data': {
        'Username': displayName,
        'ConnectionId': threadId
      },
      'to': pushToken,
      'android': {
        priority: 'high',
      },
      'priority': 'high',
      'time_to_live': 1,
      'restricted_package_name': 'com.package.name',
    }, {
      headers: {
        'Content-Type': 'application/json',
        'Authorization': 'key=' + fcmToken
      }
    });

Native code (MyFirebaseMessagingService.java):

public void onMessageReceived(RemoteMessage remoteMessage) {
  Log.d(TAG, "==> MyFirebaseMessagingService onMessageReceived");
  String username = remoteMessage.getData().get("Username");
  String connectionId = remoteMessage.getData().get("ConnectionId");
  }
}