Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My app is Getting Crashed once i start my background service please tell me whats the issue #242

Open
Yashi1919 opened this issue Sep 24, 2024 · 9 comments

Comments

@Yashi1919
Copy link

this is my android manifest.xml
please resolve this issue i have to upload this in oplaystore please

<!-- Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<!-- Foreground Service Permissions -->
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" tools:targetApi="m" />

<!-- Location Permissions -->
<!-- ACCESS_FINE_LOCATION allows fine (GPS) location access -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- ACCESS_BACKGROUND_LOCATION should be requested only if your app truly requires background location access -->
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
    tools:targetApi="r" />

<!-- Storage Permissions - Use Scoped Storage instead of broad permissions -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" tools:targetApi="30"/>

<application
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/wallo"
    android:roundIcon="@mipmap/wallo"
    android:allowBackup="false"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">

    <!-- Main Activity -->
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <intent-filter android:label="filter_react_native">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="wallodynamo" />
        </intent-filter>
    </activity>

    <!-- Foreground Service Declaration -->
    <service
        android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask"
        android:exported="false"
        android:foregroundServiceType="location|mediaPlayback|dataSync"
        android:permission="android.permission.BIND_JOB_SERVICE"
        tools:replace="android:foregroundServiceType">
    </service>


</application>
@mikkeldanielsen
Copy link

You need foreground service permissions for every foreground service type, that you use.

For instance I use dataSync and Microphone

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />

@Yashi1919
Copy link
Author

<!-- Existing permissions -->
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>                                                                                                                  
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<!-- Add permissions for specific foreground service types -->
<!-- Example for Camera Service -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- Add other specific permissions as needed -->

<application
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/wallo"
    android:roundIcon="@mipmap/wallo"
    android:allowBackup="false"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter android:label="filter_react_native">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="wallodynamo" />
        </intent-filter>
    </activity>

    <!-- Service Declaration -->
    <service
        android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask"
        android:exported="false"
        android:foregroundServiceType="location|mediaPlayback|dataSync"
        android:permission="android.permission.BIND_JOB_SERVICE"
        tools:replace="android:foregroundServiceType">
    </service>

</application>
still getting crashed may i am not asking permissions can anyone help me with the permissions that i have to ask from user to run my foreground service

@chandanpradhanin
Copy link

I am also getting same issue.

@mikkeldanielsen
Copy link

<!-- Existing permissions -->
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CONNECTED_DEVICE"/>                                                                                                                  
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<!-- Add permissions for specific foreground service types -->
<!-- Example for Camera Service -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- Add other specific permissions as needed -->

<application
    android:name=".MainApplication"
    android:label="@string/app_name"
    android:icon="@mipmap/wallo"
    android:roundIcon="@mipmap/wallo"
    android:allowBackup="false"
    android:theme="@style/AppTheme"
    android:supportsRtl="true">

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
        android:launchMode="singleTask"
        android:windowSoftInputMode="adjustResize"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter android:label="filter_react_native">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="wallodynamo" />
        </intent-filter>
    </activity>

    <!-- Service Declaration -->
    <service
        android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask"
        android:exported="false"
        android:foregroundServiceType="location|mediaPlayback|dataSync"
        android:permission="android.permission.BIND_JOB_SERVICE"
        tools:replace="android:foregroundServiceType">
    </service>

</application>

still getting crashed may i am not asking permissions can anyone help me with the permissions that i have to ask from user to run my foreground service

If you use Android Studio, you can see what happens when your app crashes. In the crash/error log you should see what permission you need to request.

@chandanpradhanin
Copy link

chandanpradhanin commented Sep 27, 2024

The crash issue I encountered was resolved by following these steps:

Step 1: Reinstall the Latest Version
Ensure you are using the latest version of the lib, which is 4.0.1.

Step 2: Add Foreground Service Permissions
Include the following permissions in your AndroidManifest.xml file to allow foreground services:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

Step 3: Add Service Declaration in Manifest
In the section of your AndroidManifest.xml, add the following line to declare the foreground service. If this line already exists, ensure it is exactly as shown below:

<application>
        <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync" />
    </application>

Final Manifest Example:
After making the above changes, your manifest file should resemble this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asterinet.react.bgactions">
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
    <application>
        <service android:name=".RNBackgroundActionsTask" android:foregroundServiceType="dataSync" />
    </application>
</manifest>

These steps resolved the crash issue for me. I hope this helps others facing similar problems.

@vishalyad16
Copy link

vishalyad16 commented Oct 1, 2024

While the app is in the background, the microphone isn't working. However, it functions properly when the app is in the foreground, where both camera and microphone permissions are granted.

how can i solve this @chandanpradhanin @mikkeldanielsen @Yashi1919 ?

@vishalyad16
Copy link

You need foreground service permissions for every foreground service type, that you use.

For instance I use dataSync and Microphone

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />

How can I handle the background issue since the microphone isn’t working when the app is in the background?

@vishalyad16
Copy link

Not able to release app playstore blocking the release requesting for a video with foreground service, please help with solution! BTW why do we need FOREGROUND_SERVICE_DATA_SYNC?? @mikkeldanielsen @Yashi1919 @chandanpradhanin

@ravindraguptacapgemini
Copy link

ravindraguptacapgemini commented Oct 23, 2024

I am getting the same issue after migrating app to React Native 0.75.3 @mikkeldanielsen @Yashi1919 @chandanpradhanin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants