2

This is how my Manifest looks like:

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

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver
            android:name="ConnectivityActionReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="android.net.wifi.WIFI_STATE_CHANGE" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

My Receiver works fine when registering from activity but I want to register from manifest so that it can run even when the app is closed. What is the issue? Why is it not working?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Lcukerd
  • 438
  • 6
  • 21

2 Answers2

5

Since Android Oreo, receivers must be registered in runtime using

context.registerReceiver(receiver, intentFilter);

to receive implicit intents

You can still receive explicit intents and some special implicit actions, as boot_completed or locale_changed for example

More information look below link

https://developer.android.com/about/versions/oreo/background.html#broadcasts

Jyubin Patel
  • 1,373
  • 7
  • 17
0

Try Using .ConnectivityActionReceiver instead of ConnectivityActionReceiver. when you Call ConnectivityActionReceiver The Receiver won't be Registered Since No Class is Found

    <receiver
        android:name=".ConnectivityActionReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter android:priority="100">
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name="android.net.wifi.WIFI_STATE_CHANGE" />
        </intent-filter>
    </receiver>

Refer This Question to know More

Tomin B Azhakathu
  • 2,656
  • 1
  • 19
  • 28