Giter VIP home page Giter VIP logo

Comments (4)

kirillTolmachev avatar kirillTolmachev commented on July 28, 2024

Hello @AshwiniPore
I don't have exact advice but I guess the problem could be in not enough value for foregroundServiceType parameter.
In a foreground service, we keep a connection with a server and interact with SDK. I mean we are using the microphone and camera as well.
Please try to change the parameters for foregroundServiceType and startForegroundService to support also camera and microphone as well.
An example of possibly using you can see in a code snippet below:
AndroidManifest file:

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
    <uses-permission android:name="android.permission.CAPTURE_AUDIO_OUTPUT" />

    <application>
        <service
            android:name=".quickblox.service.CallService"
            android:exported="false"
            android:foregroundServiceType="mediaPlayback|camera|microphone" />

service class:

 @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
       //some code for build notification

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
            startForeground(SERVICE_ID, notification, getServiceType());
        } else {
            startForeground(SERVICE_ID, notification);
        }

        return super.onStartCommand(intent, flags, startId);
    }

    @RequiresApi(api = Build.VERSION_CODES.Q)
    private int getServiceType() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            return ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK | ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA | ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE;
        } else {
            return ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK;
        }
    }

Hope it will help you.

from quickblox-android-sdk.

mihAdsc avatar mihAdsc commented on July 28, 2024

Hello!
We are having the same issue after migrating to android sdk 34.
Still trying to figure @kirillTolmachev's solution, for some reason the calls are not working anymore on our side (the firebase secret keys json is successfully added and sometimes a call is getting through).
More specifically, I have two test devices, Device1 - Android 13, Device 2 - Android 14. I can call from android 13 to 14 without any issues but I cannot receive a background call, through push notifications, from Android 14 to Android 13.
I'm just wondering, @AshwiniPore did you manage to find a solution for this case?
Thanks!

from quickblox-android-sdk.

QB-maksym-pidhorbunskyi avatar QB-maksym-pidhorbunskyi commented on July 28, 2024

Hello @mihAdsc
Please try to follow the instructions below:

To solve this problem, remove the "mediaPlayback" type of the foreground service. Only types for the camera and microphone should remain android:foregroundServiceType="camera|microphone".
More information about foreground service types can be read in the official documentation Foreground service types are required | Android Developers .
To do this, you need to make changes in several files:

AndroidManifest.xml

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />

    <service
        android:name=".quickblox.service.CallService"
        android:exported="false"
        android:foregroundServiceType="camera|microphone" />

CallService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    //some code for build notification

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        startForeground(SERVICE_ID, notification,  ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA | ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE);
     } else {
        startForeground(SERVICE_ID, notification);
    }

    return super.onStartCommand(intent, flags, startId);
}

In addition, should obtain runtime-permissions Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO before starting the CallService Request runtime permissions | Android Developers

Let us know if the instructions provided helped you resolve your issue.

from quickblox-android-sdk.

mihAdsc avatar mihAdsc commented on July 28, 2024

@QB-maksym-pidhorbunskyi it worked just fine! Thank you.

from quickblox-android-sdk.

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.