QuickBlox / quickblox-android-sdk

QuickBlox Android SDK includes code snippets with main use cases and framework JAR library.
BSD 3-Clause "New" or "Revised" License
417 stars 697 forks source link

Not able to receive call when app is not running #718

Closed krishnameena closed 4 years ago

krishnameena commented 4 years ago

When app is running video call works fine but not receiving calls when app is not running on remote device.

krishnameena commented 4 years ago

Got it working had some issues with Firebase notifications.

nikunjmi commented 4 years ago

@krishnameena I have same issue so can you please explain what is the issue in Firebase notifications or do i need to change anything with firebse console. Can you please help me to solve this issue.

Thanks.

krishnameena commented 4 years ago

Share your manifest file

nikunjmi commented 4 years ago

@krishnameena Can you please check manifest file?

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.project">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.VIBRATE" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application
    android:name=".presenter.app.AppController"
    android:allowBackup="false"
    tools:replace="android:allowBackup"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:usesCleartextTraffic="true"
    android:requestLegacyExternalStorage="true"
    android:theme="@style/AppTheme">
    <service
        android:name="org.eclipse.paho.android.service.MqttService"
        android:exported="false" />

    <activity android:name=".presenter.splash.SplashActivity"
        android:theme="@style/SplashTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name=".presenter.lrf.activity.LrfActivity"
        android:windowSoftInputMode="adjustPan"/>

    <activity android:name=".presenter.main.MainActivity" />
    <activity android:name=".comman.MIGoogleActivity" />
    <activity android:name=".comman.MIFacebookActivity" />

    <activity
        android:name=".quickbox.activities.PermissionsActivity"
        android:screenOrientation="portrait" />

    <activity
        android:name=".quickbox.activities.CallActivity"
        android:configChanges="keyboardHidden|screenSize|orientation"
        android:excludeFromRecents="true"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme" />

    <service android:name=".quickbox.service.LoginService"
        android:enabled="true"
        android:exported="false">
    </service>

    <service android:name=".quickbox.service.CallService"
        android:enabled="true"
        android:exported="false">
    </service>

    <service android:name=".quickbox.service.fcm.PushListenerService"
        tools:ignore="Instantiatable">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <service android:name="com.quickblox.messages.services.fcm.QBFcmPushInstanceIDService"
        tools:ignore="Instantiatable">
        <intent-filter>
            <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
        </intent-filter>
    </service>

    <meta-data
        android:name="com.quickblox.messages.TYPE"
        android:value="FCM" />

    <meta-data
        android:name="com.quickblox.messages.SENDER_ID"
        android:value="@string/sender_id" />

    <meta-data
        android:name="com.quickblox.messages.QB_ENVIRONMENT"
        android:value="DEVELOPMENT" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />

    <meta-data
        android:name="firebase_crashlytics_collection_enabled"
        android:value="${isEnableCrashlytics}" />

    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_map_key" />

    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id" />

    <service
        android:name=".comman.service.push.MyFirebaseInstanceIDService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

</application>

krishnameena commented 4 years ago

You have registered 2 services for same event

remove this

<service
        android:name=".comman.service.push.MyFirebaseInstanceIDService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

Then check logs whether FCM event is receiving or not then implement logic accordingly

krishnameena commented 4 years ago

Also post your PushListenerService code

nikunjmi commented 4 years ago

PushListenerService code

class PushListenerService : QBFcmPushListenerService() { private val TAG = PushListenerService::class.java.simpleName

override fun onNewToken(token: String) {
    super.onNewToken(token)
    val intent = Intent(Const.ACTION_TOKEN_CHANGED)
    intent.putExtra(Const.BUNDLE_NOTIFICATION_ID, token)
    LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
    val tokenRefreshed = true
    SubscribeService.subscribeToPushes(AppController.appContext, tokenRefreshed)
}

override fun onMessageReceived(remoteMessage: RemoteMessage) {
    super.onMessageReceived(remoteMessage)
    if (SharedPrefsHelper.hasQbUser()) {
        val qbUser: QBUser = SharedPrefsHelper.getQbUser()
        Log.d(TAG, "App has logged user" + qbUser.id)
        LoginService.start(AppController.appContext, qbUser)
    }
}

override fun sendPushMessage(data: MutableMap<Any?, Any?>?, from: String?, message: String?) {
    super.sendPushMessage(data, from, message)
    Log.v(TAG, "From: $from")
    Log.v(TAG, "Message: $message")
}

}

krishnameena commented 4 years ago

Add this to sendPushMessage method

if (SharedPrefsHelper.hasQbUser()) {
        val qbUser: QBUser = SharedPrefsHelper.getQbUser()
        Log.d(TAG, "App has logged user" + qbUser.id)
        LoginService.start(AppController.appContext, qbUser)
    }
nikunjmi commented 4 years ago

I added this LoginSerivce start code into sendPushMessage method but still not receive incoming call when app is killed event not receive any remote message into onMessageReceived Method.

krishnameena commented 4 years ago

You are missing following permissions

<uses-permission android:name="yourpackagename.permission.C2D_MESSAGE" />
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
nikunjmi commented 4 years ago

@krishnameena I added these permissions but still not receiving video call when app is killed.

Actually problem is when app is killed "onMessageReceived" method not called so might be some issue with notification payload.

Can you please help me to figure out what is the reason behind this?

krishnameena commented 4 years ago

Please check QBFcmPushListenerService onMessageReceived it calls sendPushMessage so in PushListenerService sendPushMessage will gets called instead of onMessageReceived

krishnameena commented 4 years ago

to further debug implement QBPushManager.QBSubscribeListener and check whether subscription created or not

krishnameena commented 4 years ago

Rest check your code you might be missing something otherwise it should work